Skip to content

Instantly share code, notes, and snippets.

@peatiscoding
Last active August 9, 2020 02:19
Show Gist options
  • Save peatiscoding/dacc35d4a1756bf0c9c810870545bc55 to your computer and use it in GitHub Desktop.
Save peatiscoding/dacc35d4a1756bf0c9c810870545bc55 to your computer and use it in GitHub Desktop.
A Fixing nuxt SSR when the proxy do not pass over the complete URL path to your service.
const buildTimeConfig = {
base: process.env.APP_BASE_PATH || '/',
}
export default {
env: {
...buildTimeConfig
},
serverMiddleware: [
{
prefix: false,
route: '/',
handler: (req, res, next) => {
const regex = new RegExp(`^${buildTimeConfig.base}`)
//
if (!regex.test(req.url)) {
const dest = req.url.replace(/^\//, buildTimeConfig.base)
console.log('Rewrite', req.url, 'to', dest)
req.url = dest
}
next()
}
}
],
head: {
titleTemplate: 'Project behind proxy',
link: [
{ rel: 'icon', type: 'image/x-icon', href: 'favicon.ico' },
{
rel: 'stylesheet',
href: `${buildTimeConfig.base}css/bootstrap.min.css`
},
{
rel: 'stylesheet',
href: 'https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css'
},
]
},
static: {
prefix: true,
},
build: {
publicPath: `${buildTimeConfig.base}_nuxt/`
},
router: {
base: buildTimeConfig.base
},
buildModules: ['@nuxt/typescript-build'],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment