From 69dd82d329f63f54a41ef658b503bb58be3f6ed4 Mon Sep 17 00:00:00 2001 From: mikiher Date: Sat, 12 Oct 2024 11:18:49 +0300 Subject: [PATCH 1/7] Remove unneeded /dev routing --- client/nuxt.config.js | 3 +-- client/plugins/axios.js | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/client/nuxt.config.js b/client/nuxt.config.js index 0bca2a14..1954696e 100644 --- a/client/nuxt.config.js +++ b/client/nuxt.config.js @@ -72,8 +72,7 @@ module.exports = { ], proxy: { - '/api/': { target: process.env.NODE_ENV !== 'production' ? 'http://localhost:3333' : '/' }, - '/dev/': { target: 'http://localhost:3333', pathRewrite: { '^/dev/': '' } } + [`${process.env.ROUTER_BASE_PATH || ''}/api/`]: { target: process.env.NODE_ENV !== 'production' ? 'http://localhost:3333' : '/' } }, io: { diff --git a/client/plugins/axios.js b/client/plugins/axios.js index 4ea9b85b..c068c4e9 100644 --- a/client/plugins/axios.js +++ b/client/plugins/axios.js @@ -13,7 +13,6 @@ export default function ({ $axios, store, $config }) { } if (process.env.NODE_ENV === 'development') { - config.url = `/dev${config.url}` console.log('Making request to ' + config.url) } }) From 99ffd3050c2d5a08efc2cd9dd56eec77fa042083 Mon Sep 17 00:00:00 2001 From: mikiher Date: Sat, 12 Oct 2024 11:46:44 +0300 Subject: [PATCH 2/7] Cleanup: Define routerBasePath constant in nuxt.config.js --- client/nuxt.config.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/client/nuxt.config.js b/client/nuxt.config.js index 1954696e..2b48971f 100644 --- a/client/nuxt.config.js +++ b/client/nuxt.config.js @@ -1,19 +1,21 @@ const pkg = require('./package.json') +const routerBasePath = process.env.ROUTER_BASE_PATH || '' + module.exports = { // Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode ssr: false, target: 'static', dev: process.env.NODE_ENV !== 'production', env: { - serverUrl: process.env.NODE_ENV === 'production' ? process.env.ROUTER_BASE_PATH || '' : 'http://localhost:3333', + serverUrl: process.env.NODE_ENV === 'production' ? routerBasePath : 'http://localhost:3333', chromecastReceiver: 'FD1F76C5' }, telemetry: false, publicRuntimeConfig: { version: pkg.version, - routerBasePath: process.env.ROUTER_BASE_PATH || '' + routerBasePath }, // Global page headers: https://go.nuxtjs.dev/config-head @@ -30,13 +32,13 @@ module.exports = { ], script: [], link: [ - { rel: 'icon', type: 'image/x-icon', href: (process.env.ROUTER_BASE_PATH || '') + '/favicon.ico' }, - { rel: 'apple-touch-icon', href: (process.env.ROUTER_BASE_PATH || '') + '/ios_icon.png' } + { rel: 'icon', type: 'image/x-icon', href: routerBasePath + '/favicon.ico' }, + { rel: 'apple-touch-icon', href: routerBasePath + '/ios_icon.png' } ] }, router: { - base: process.env.ROUTER_BASE_PATH || '' + base: routerBasePath }, // Global CSS: https://go.nuxtjs.dev/config-css @@ -72,7 +74,7 @@ module.exports = { ], proxy: { - [`${process.env.ROUTER_BASE_PATH || ''}/api/`]: { target: process.env.NODE_ENV !== 'production' ? 'http://localhost:3333' : '/' } + [`${routerBasePath}/api/`]: { target: process.env.NODE_ENV !== 'production' ? 'http://localhost:3333' : '/' } }, io: { @@ -87,7 +89,7 @@ module.exports = { // Axios module configuration: https://go.nuxtjs.dev/config-axios axios: { - baseURL: process.env.ROUTER_BASE_PATH || '' + baseURL: routerBasePath }, // nuxt/pwa https://pwa.nuxtjs.org @@ -107,11 +109,11 @@ module.exports = { background_color: '#232323', icons: [ { - src: (process.env.ROUTER_BASE_PATH || '') + '/icon.svg', + src: routerBasePath + '/icon.svg', sizes: 'any' }, { - src: (process.env.ROUTER_BASE_PATH || '') + '/icon192.png', + src: routerBasePath + '/icon192.png', type: 'image/png', sizes: 'any' } From 241c02be30f584791a37a542802503c2349e051f Mon Sep 17 00:00:00 2001 From: mikiher Date: Mon, 14 Oct 2024 13:12:10 +0300 Subject: [PATCH 3/7] nuxt.config.js: more cleanup and additional proxies --- client/nuxt.config.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/client/nuxt.config.js b/client/nuxt.config.js index 2b48971f..f3c8641c 100644 --- a/client/nuxt.config.js +++ b/client/nuxt.config.js @@ -1,6 +1,7 @@ const pkg = require('./package.json') const routerBasePath = process.env.ROUTER_BASE_PATH || '' +const serverHostUrl = process.env.NODE_ENV === 'production' ? '' : 'http://localhost:3333' module.exports = { // Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode @@ -8,7 +9,7 @@ module.exports = { target: 'static', dev: process.env.NODE_ENV !== 'production', env: { - serverUrl: process.env.NODE_ENV === 'production' ? routerBasePath : 'http://localhost:3333', + serverUrl: serverHostUrl + routerBasePath, chromecastReceiver: 'FD1F76C5' }, telemetry: false, @@ -74,13 +75,15 @@ module.exports = { ], proxy: { - [`${routerBasePath}/api/`]: { target: process.env.NODE_ENV !== 'production' ? 'http://localhost:3333' : '/' } + [`${routerBasePath}/api/`]: { target: process.env.NODE_ENV !== 'production' ? serverHostUrl : '/' }, + [`${routerBasePath}/public/`]: { target: process.env.NODE_ENV !== 'production' ? serverHostUrl : '/' }, + [`${routerBasePath}/hls/`]: { target: process.env.NODE_ENV !== 'production' ? serverHostUrl : '/' } }, io: { sockets: [{ name: 'dev', - url: 'http://localhost:3333' + url: serverHostUrl }, { name: 'prod' From 42616b59de16c21721137accb3078874ef90008d Mon Sep 17 00:00:00 2001 From: mikiher Date: Mon, 14 Oct 2024 13:30:17 +0300 Subject: [PATCH 4/7] Cleanup: remove explicit localhost:3333 and remove unnessesary if(dev) blocks --- client/components/covers/AuthorImage.vue | 6 +----- client/components/modals/ShareModal.vue | 4 ++-- client/components/modals/rssfeed/OpenCloseModal.vue | 2 +- client/pages/audiobook/_id/chapters.vue | 2 +- client/players/AudioTrack.js | 4 ---- client/store/globals.js | 10 ---------- 6 files changed, 5 insertions(+), 23 deletions(-) diff --git a/client/components/covers/AuthorImage.vue b/client/components/covers/AuthorImage.vue index af8a394f..01926363 100644 --- a/client/components/covers/AuthorImage.vue +++ b/client/components/covers/AuthorImage.vue @@ -56,11 +56,7 @@ export default { }, imgSrc() { if (!this.imagePath) return null - if (process.env.NODE_ENV !== 'production') { - // Testing - return `http://localhost:3333${this.$config.routerBasePath}/api/authors/${this.authorId}/image?token=${this.userToken}&ts=${this.updatedAt}` - } - return `/api/authors/${this.authorId}/image?token=${this.userToken}&ts=${this.updatedAt}` + return `${this.$config.routerBasePath}/api/authors/${this.authorId}/image?token=${this.userToken}&ts=${this.updatedAt}` } }, methods: { diff --git a/client/components/modals/ShareModal.vue b/client/components/modals/ShareModal.vue index 65ef4fc7..d0487fd3 100644 --- a/client/components/modals/ShareModal.vue +++ b/client/components/modals/ShareModal.vue @@ -112,11 +112,11 @@ export default { return this.$store.state.user.user }, demoShareUrl() { - return `${window.origin}/share/${this.newShareSlug}` + return `${window.origin}${this.$config.routerBasePath}/share/${this.newShareSlug}` }, currentShareUrl() { if (!this.currentShare) return '' - return `${window.origin}/share/${this.currentShare.slug}` + return `${window.origin}${this.$config.routerBasePath}/share/${this.currentShare.slug}` }, currentShareTimeRemaining() { if (!this.currentShare) return 'Error' diff --git a/client/components/modals/rssfeed/OpenCloseModal.vue b/client/components/modals/rssfeed/OpenCloseModal.vue index f15a8e8e..53542cf5 100644 --- a/client/components/modals/rssfeed/OpenCloseModal.vue +++ b/client/components/modals/rssfeed/OpenCloseModal.vue @@ -139,7 +139,7 @@ export default { slug: this.newFeedSlug, metadataDetails: this.metadataDetails } - if (this.$isDev) payload.serverAddress = `http://localhost:3333${this.$config.routerBasePath}` + if (this.$isDev) payload.serverAddress = process.env.serverUrl console.log('Payload', payload) this.$axios diff --git a/client/pages/audiobook/_id/chapters.vue b/client/pages/audiobook/_id/chapters.vue index 3448479b..43d64b90 100644 --- a/client/pages/audiobook/_id/chapters.vue +++ b/client/pages/audiobook/_id/chapters.vue @@ -415,7 +415,7 @@ export default { const audioEl = this.audioEl || document.createElement('audio') var src = audioTrack.contentUrl + `?token=${this.userToken}` if (this.$isDev) { - src = `http://localhost:3333${this.$config.routerBasePath}${src}` + src = `${process.env.serverUrl}${src}` } audioEl.src = src diff --git a/client/players/AudioTrack.js b/client/players/AudioTrack.js index 78ddfd76..9627d3cd 100644 --- a/client/players/AudioTrack.js +++ b/client/players/AudioTrack.js @@ -23,10 +23,6 @@ export default class AudioTrack { get relativeContentUrl() { if (!this.contentUrl || this.contentUrl.startsWith('http')) return this.contentUrl - if (process.env.NODE_ENV === 'development') { - return `${process.env.serverUrl}${this.contentUrl}?token=${this.userToken}` - } - return this.contentUrl + `?token=${this.userToken}` } } diff --git a/client/store/globals.js b/client/store/globals.js index 8e98c56d..553301f5 100644 --- a/client/store/globals.js +++ b/client/store/globals.js @@ -98,12 +98,6 @@ export const getters = { const userToken = rootGetters['user/getToken'] const lastUpdate = libraryItem.updatedAt || Date.now() const libraryItemId = libraryItem.libraryItemId || libraryItem.id // Workaround for /users/:id page showing media progress covers - - if (process.env.NODE_ENV !== 'production') { - // Testing - return `http://localhost:3333${rootState.routerBasePath}/api/items/${libraryItemId}/cover?token=${userToken}&ts=${lastUpdate}${raw ? '&raw=1' : ''}` - } - return `${rootState.routerBasePath}/api/items/${libraryItemId}/cover?token=${userToken}&ts=${lastUpdate}${raw ? '&raw=1' : ''}` }, getLibraryItemCoverSrcById: @@ -112,10 +106,6 @@ export const getters = { const placeholder = `${rootState.routerBasePath}/book_placeholder.jpg` if (!libraryItemId) return placeholder const userToken = rootGetters['user/getToken'] - if (process.env.NODE_ENV !== 'production') { - // Testing - return `http://localhost:3333${rootState.routerBasePath}/api/items/${libraryItemId}/cover?token=${userToken}${raw ? '&raw=1' : ''}${timestamp ? `&ts=${timestamp}` : ''}` - } return `${rootState.routerBasePath}/api/items/${libraryItemId}/cover?token=${userToken}${raw ? '&raw=1' : ''}${timestamp ? `&ts=${timestamp}` : ''}` }, getIsBatchSelectingMediaItems: (state) => { From 2d7b63b4cf3d5baaa7f229d4669f3d464dba2685 Mon Sep 17 00:00:00 2001 From: mikiher Date: Tue, 15 Oct 2024 05:50:23 +0300 Subject: [PATCH 5/7] Add base path to socket.io connections on client and server --- client/layouts/default.vue | 3 ++- server/SocketAuthority.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/client/layouts/default.vue b/client/layouts/default.vue index 95f8560d..9121561e 100644 --- a/client/layouts/default.vue +++ b/client/layouts/default.vue @@ -357,7 +357,8 @@ export default { teardown: false, transports: ['websocket'], upgrade: false, - reconnection: true + reconnection: true, + path: `${this.$config.routerBasePath}/socket.io` }) this.$root.socket = this.socket console.log('Socket initialized') diff --git a/server/SocketAuthority.js b/server/SocketAuthority.js index af8204c6..a7182936 100644 --- a/server/SocketAuthority.js +++ b/server/SocketAuthority.js @@ -103,7 +103,8 @@ class SocketAuthority { cors: { origin: '*', methods: ['GET', 'POST'] - } + }, + path: `${global.RouterBasePath}/socket.io` }) this.io.on('connection', (socket) => { From cbca560f9248d2b1c798c3d014177372bff6b37e Mon Sep 17 00:00:00 2001 From: mikiher Date: Tue, 15 Oct 2024 06:40:14 +0300 Subject: [PATCH 6/7] server.js: add base path to all non-base-path requests --- server/Server.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server/Server.js b/server/Server.js index 7e541e61..d8265237 100644 --- a/server/Server.js +++ b/server/Server.js @@ -243,6 +243,15 @@ class Server { await this.auth.initPassportJs() const router = express.Router() + // if RouterBasePath is set, modify all requests to include the base path + if (global.RouterBasePath) { + app.use((req, res, next) => { + if (!req.url.startsWith(global.RouterBasePath)) { + req.url = `${global.RouterBasePath}${req.url}` + } + next() + }) + } app.use(global.RouterBasePath, router) app.disable('x-powered-by') @@ -340,7 +349,7 @@ class Server { Logger.info('Received ping') res.json({ success: true }) }) - app.get('/healthcheck', (req, res) => res.sendStatus(200)) + router.get('/healthcheck', (req, res) => res.sendStatus(200)) this.server.listen(this.Port, this.Host, () => { if (this.Host) Logger.info(`Listening on http://${this.Host}:${this.Port}`) From cb85e0255bc4ba2c57cd3b5db466a289f1173dcc Mon Sep 17 00:00:00 2001 From: advplyr Date: Tue, 15 Oct 2024 16:52:04 -0500 Subject: [PATCH 7/7] Fix share URLs on dev --- client/pages/share/_slug.vue | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/client/pages/share/_slug.vue b/client/pages/share/_slug.vue index f4f93b1d..cd990072 100644 --- a/client/pages/share/_slug.vue +++ b/client/pages/share/_slug.vue @@ -61,16 +61,10 @@ export default { }, coverUrl() { if (!this.playbackSession.coverPath) return `${this.$config.routerBasePath}/book_placeholder.jpg` - if (process.env.NODE_ENV === 'development') { - return `http://localhost:3333/public/share/${this.mediaItemShare.slug}/cover` - } - return `/public/share/${this.mediaItemShare.slug}/cover` + return `${this.$config.routerBasePath}/public/share/${this.mediaItemShare.slug}/cover` }, audioTracks() { return (this.playbackSession.audioTracks || []).map((track) => { - if (process.env.NODE_ENV === 'development') { - track.contentUrl = `${process.env.serverUrl}${track.contentUrl}` - } track.relativeContentUrl = track.contentUrl return track })