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/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/client/nuxt.config.js b/client/nuxt.config.js index 0bca2a14..f3c8641c 100644 --- a/client/nuxt.config.js +++ b/client/nuxt.config.js @@ -1,19 +1,22 @@ 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 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: serverHostUrl + routerBasePath, 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 +33,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,14 +75,15 @@ module.exports = { ], proxy: { - '/api/': { target: process.env.NODE_ENV !== 'production' ? 'http://localhost:3333' : '/' }, - '/dev/': { target: 'http://localhost:3333', pathRewrite: { '^/dev/': '' } } + [`${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' @@ -88,7 +92,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 @@ -108,11 +112,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' } 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/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 }) 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/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) } }) 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) => { 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}`) 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) => {