From 6b0f0883eecebd5c9e867b6878f24e1612f5a335 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 10 May 2023 02:27:01 +0200 Subject: [PATCH] A proper way to proxy websocket calls using the Vue devServer. --- platypush/backend/http/webapp/vue.config.js | 52 +++++++++++---------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/platypush/backend/http/webapp/vue.config.js b/platypush/backend/http/webapp/vue.config.js index 5596fde4c6..b4db0f6587 100644 --- a/platypush/backend/http/webapp/vue.config.js +++ b/platypush/backend/http/webapp/vue.config.js @@ -1,4 +1,21 @@ +const httpProxy = { + target: 'http://localhost:8008', + changeOrigin: true +} + +const wsProxy = { + target: 'http://localhost:8008', + changeOrigin: false, + ws: true, + onProxyReq: function(request) { + console.log('===== HERE'); + console.log(request); + request.setHeader('Origin', 'http://localhost:8008'); + }, +} + module.exports = { + lintOnSave: true, outputDir: "dist", assetsDir: "static", css: { @@ -14,31 +31,16 @@ module.exports = { devServer: { proxy: { - '/execute': { - target: 'http://localhost:8008', - changeOrigin: true - }, - '/ws/events': { - target: 'http://localhost:8008', - ws: true, - changeOrigin: true - }, - '/auth': { - target: 'http://localhost:8008', - changeOrigin: true - }, - '/logout': { - target: 'http://localhost:8008', - changeOrigin: true - }, - '/camera/*': { - target: 'http://localhost:8008', - changeOrigin: true - }, - '/sound/*': { - target: 'http://localhost:8008', - changeOrigin: true - } + '/execute': httpProxy, + '/ws/events': wsProxy, + '/ws/requests': wsProxy, + '/static/*': httpProxy, + '/auth': httpProxy, + '/login': httpProxy, + '/logout': httpProxy, + '/register': httpProxy, + '/camera/*': httpProxy, + '/sound/*': httpProxy, } } };