Support SPA mode

husayt
405
husayt
commented a year ago

From what I understand this doesn't work without node/express.

is SPA mode support in plans?

0
pi0
20.0k
pi0
commented a year ago

Hi. Hmm not totally but this middleware partially should work for spa when starting with nuxt start too. Are you trying to statically host generated files?

0
husayt
405
husayt
commented a year ago

Yes, indeed I am looking solution for static website. Actually, I found what I needed.

https://github.com/nuxt/hackernews/blob/master/middleware/https.js

Will be very useful to at least mention this here or maybe make it part of the solution.

0
pi0
20.0k
pi0
commented a year ago

For static serving, most cloud providers like surge or CloudFlare support ssl redirect and also there is easy nginx configurations forcing SSL. While that https middleware works, i highly recommend using those high level configurations to enable HTS which is much more secure and stable for production use cases.

BTW PRs welcome for mentioning about middleware both here and in official docs repo.

0
husayt
405
husayt
commented a year ago

Yes, indeed having server side redirect is preferred. But let's say I don't have that option and i have an spa, i need to get redirected from client.

I have tried what was in hackernews demo app, but that doesn't work. I hace registered the method below as middleware and req is always undefined. Do I miss anything?

export default ({ isDev, req, redirect }) => {
        // Redirect to https
    if (!isDev && req) {
        const protocol = req.headers['x-forwarded-proto'] || (req.connection.encrypted ? 'https' : 'http')
        if (protocol === 'http') {
            return redirect(301, `https://${req.headers.host}${req.url}`)
        }
    }
}
0
pSchaub
90
pSchaub
commented 9 months ago

Nuxt supports spa mode: https://nuxtjs.org/api/configuration-mode/
After enabling it the nuxt build command will generate static files in the dist folder.

0
Informations
Question โ€ข Unresolved
#c2 - Created a year ago