Change AppScriptServlet configuration

This commit is contained in:
Damien Corneau 2015-07-01 19:49:46 +09:00
parent ef764fce52
commit 0addb806a6
3 changed files with 23 additions and 30 deletions

View file

@ -41,7 +41,7 @@ public class AppScriptServlet extends DefaultServlet {
private static Set<String> scriptPaths = new HashSet<String>(
Arrays.asList(
"/scripts/scripts.js",
"/scripts/app.js"
"/components/baseUrl/baseUrl.js"
)
);
@ -77,14 +77,16 @@ public class AppScriptServlet extends DefaultServlet {
script.append(new String(buffer, 0, numRead, "UTF-8"));
}
// Replace the string "function getPort(){...}" to return
// the proper value
int startIndex = script.indexOf("function getPort()");
int endIndex = script.indexOf("}", startIndex);
// Replace the getPort function to return the proper value
String startReplaceString = "/* @preserve AppScriptServlet - getPort */";
String endReplaceString = "/* @preserve AppScriptServlet - close */";
int startIndex = script.indexOf(startReplaceString);
int endIndex = script.indexOf(endReplaceString, startIndex);
if (startIndex >= 0 && endIndex >= 0) {
String replaceString = "function getPort(){return " + websocketPort + "}";
script.replace(startIndex, endIndex + 1, replaceString);
String replaceString = "this.getPort=function(){return " + websocketPort + "};";
script.replace(startIndex, endIndex + endReplaceString.length(), replaceString);
}
response.getWriter().println(script.toString());

View file

@ -16,29 +16,7 @@
*/
'use strict';
/** Get the current port of the websocket
*
* In the case of running the zeppelin-server normally,
* the body of this function is just filler. It will be dynamically
* overridden with the AppScriptServlet from zeppelin-site.xml config value
* when the client requests the script.
*
* If the config value is not defined, it defaults to the HTTP port + 1
*
* At the moment, the key delimiter denoting the end of this function
* during the replacement is the '}' character.
*
* !!!
* Avoid using '}' inside the function body or you will fail running
* in server mode.
* !!!
*
* In the case of running "grunt serve", this function will appear
* as is.
*/
angular
.module('zeppelinWebApp', [
angular.module('zeppelinWebApp', [
'ngAnimate',
'ngCookies',
'ngRoute',

View file

@ -15,6 +15,18 @@
angular.module('zeppelinWebApp').service('baseUrlSrv', function() {
/** Get the current port of the websocket
*
* When running Zeppelin, the body of this function will be dynamically
* overridden with the AppScriptServlet from zeppelin-site.xml config value.
*
* If the config value is not defined, it defaults to the HTTP port + 1
*
* In the case of running "grunt serve", this function will appear
* as is.
*/
/* @preserve AppScriptServlet - getPort */
this.getPort = function() {
var port = Number(location.port);
if (location.protocol !== 'https:' && (port === 'undifined' || port === 0)) {
@ -26,6 +38,7 @@ angular.module('zeppelinWebApp').service('baseUrlSrv', function() {
}
return port+1;
};
/* @preserve AppScriptServlet - close */
this.getWebsocketProtocol = function() {
var protocol = 'ws';