Skip to content

Commit 7f8bc47

Browse files
committed
Cleanup of Javascript logic and Server code detecting the correct port
1 parent 412927f commit 7f8bc47

File tree

4 files changed

+16
-129
lines changed

4 files changed

+16
-129
lines changed

zeppelin-server/src/main/java/org/apache/zeppelin/server/AppScriptServlet.java

Lines changed: 0 additions & 94 deletions
This file was deleted.

zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.eclipse.jetty.server.nio.SelectChannelConnector;
4949
import org.eclipse.jetty.server.session.SessionHandler;
5050
import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
51+
import org.eclipse.jetty.servlet.DefaultServlet;
5152
import org.eclipse.jetty.servlet.FilterHolder;
5253
import org.eclipse.jetty.servlet.ServletContextHandler;
5354
import org.eclipse.jetty.servlet.ServletHolder;
@@ -91,7 +92,7 @@ public static void main(String[] args) throws Exception {
9192
* But the rest of swagger is configured here
9293
*/
9394
final ServletContextHandler swagger = setupSwaggerContextHandler(conf);
94-
95+
9596
// Notebook server
9697
final ServletContextHandler notebook = setupNotebookServer(conf);
9798

@@ -272,7 +273,7 @@ private static WebAppContext setupWebAppContext(
272273
}
273274
// Explicit bind to root
274275
webApp.addServlet(
275-
new ServletHolder(new AppScriptServlet()),
276+
new ServletHolder(new DefaultServlet()),
276277
"/*"
277278
);
278279
return webApp;

zeppelin-web/src/components/baseUrl/baseUrl.service.js

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,30 @@
1515

1616
angular.module('zeppelinWebApp').service('baseUrlSrv', function() {
1717

18-
/** Get the current port of the websocket
19-
*
20-
* When running Zeppelin, the body of this function will be dynamically
21-
* overridden with the AppScriptServlet from zeppelin-site.xml config value.
22-
*
23-
* If the config value is not defined, it defaults to the HTTP port + 1
24-
*
25-
* In the case of running "grunt serve", this function will appear
26-
* as is.
27-
*/
28-
29-
/* @preserve AppScriptServlet - getPort */
3018
this.getPort = function() {
31-
var port = Number(location.port);
32-
if (location.protocol !== 'https:' && !port) {
33-
port = 80;
34-
} else if (location.protocol === 'https:' && !port) {
35-
port = 443;
36-
} else if (port === 3333 || port === 9000) {
37-
port = 8080;
38-
}
39-
return port;
40-
};
41-
/* @preserve AppScriptServlet - close */
42-
43-
this.getWebsocketProtocol = function() {
44-
return location.protocol === 'https:' ? 'wss' : 'ws';
45-
};
46-
47-
this.getRestApiBase = function() {
4819
var port = Number(location.port);
4920
if (!port) {
5021
port = 80;
5122
if (location.protocol === 'https:') {
5223
port = 443;
5324
}
5425
}
55-
26+
//Exception for when running locally via grunt
5627
if (port === 3333 || port === 9000) {
5728
port = 8080;
5829
}
59-
return location.protocol + '//' + location.hostname + ':' + port + skipTrailingSlash(location.pathname) + '/api';
30+
return port;
31+
};
32+
33+
this.getWebsocketUrl = function() {
34+
var wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
35+
return wsProtocol + '//' + location.hostname + ':' + this.getPort() + '/ws';
6036
};
61-
37+
38+
this.getRestApiBase = function() {
39+
return location.protocol + '//' + location.hostname + ':' + this.getPort() + skipTrailingSlash(location.pathname) + '/api';
40+
};
41+
6242
var skipTrailingSlash = function(path) {
6343
return path.replace(/\/$/, '');
6444
};

zeppelin-web/src/components/websocketEvents/websocketEvents.factory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
angular.module('zeppelinWebApp').factory('websocketEvents', function($rootScope, $websocket, baseUrlSrv) {
1717
var websocketCalls = {};
1818

19-
websocketCalls.ws = $websocket(baseUrlSrv.getWebsocketProtocol() + '://' + location.hostname + ':' + baseUrlSrv.getPort() + '/ws');
19+
websocketCalls.ws = $websocket(baseUrlSrv.getWebsocketUrl());
2020

2121
websocketCalls.ws.onOpen(function() {
2222
console.log('Websocket created');

0 commit comments

Comments
 (0)