Skip to content

Commit

Permalink
Fix WebSockets Path vs. Namespace Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
asymworks committed Dec 14, 2020
1 parent 3b48c0a commit e79fa4d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ ENV JADETREE_API_HOST backend
ENV JADETREE_API_PORT 5000
ENV JADETREE_API_PATH /api/v1
ENV JADETREE_API_SCHEME http
ENV JADETREE_WS_PATH /socket.io
EXPOSE 80
4 changes: 3 additions & 1 deletion docker/config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"apiurl": "/api"
"apiurl": "/api",
"ws_url": "/socket.io",
"ws_namespace": "/"
}
2 changes: 1 addition & 1 deletion docker/nginx.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ server {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass ${JADETREE_API_SCHEME}://jadetree_api/socket.io;
proxy_pass ${JADETREE_API_SCHEME}://jadetree_api${JADETREE_WS_PATH};
}

error_page 500 502 503 504 /50x.html;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jadetree/frontend",
"version": "0.9.15-alpha",
"version": "0.9.16-alpha",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand Down
4 changes: 3 additions & 1 deletion public/config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"apiurl": "http://localhost:5000/api/v1"
"apiurl": "http://localhost:5000/api/v1",
"ws_url": "http://localhost:5000/socket.io",
"ws_namespace": "/"
}
13 changes: 10 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import VTooltip from 'v-tooltip';
import VueFormulate from '@braid/vue-formulate';
import VueSocketIOExt from 'vue-socket.io-extended';
import { JtControls, JtFormulateLibrary } from '@jadetree/controls';
import io from 'socket.io-client';
import { Manager } from 'socket.io-client';

// Load API
import api from './api';
Expand All @@ -24,6 +24,8 @@ import App from './App.vue';
// Configuration Schema
type JadeTreeConfig = {
apiurl: string;
ws_url?: string;
ws_namespace?: string;
};

// Configuration Loader
Expand Down Expand Up @@ -87,9 +89,14 @@ async function startup() {
}

api.baseUrl = config.apiurl;
api.socket = io(config.apiurl, { autoConnect: false });

// Setup SocketIO
// Setup WebSockets
const wsUrl = config.ws_url || config.apiurl;
const wsNamespace = config.ws_namespace || '/';
const manager = new Manager(wsUrl, { autoConnect: false });

api.socket = manager.socket(wsNamespace);

Vue.use(VueSocketIOExt, api.socket);

// Initialize Vuex Modules
Expand Down

0 comments on commit e79fa4d

Please sign in to comment.