-
Notifications
You must be signed in to change notification settings - Fork 505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cors support for route rules #95
Comments
@pi0 What about enabling cors in general? I created another thread under Nuxt and the suggested approach was to create a Nitro plugin. I could however not get it to work the same way it works for express. This is the code that works with an express server (notice the origin value set to localhost:3100). The client can access the end points just fine: app.use(
cors({
origin: 'http://localhost:3100',
credentials: true,
})
)
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', 'http://localhost:3100')
res.header('Access-Control-Allow-Credentials', true)
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
res.header(
'Access-Control-Allow-Headers',
'Origin,X-Requested-With,Content-Type,Accept,content-type,application/json'
)
next()
}) The corresponding Nitro plugin does not work. Maybe I messed up somewhere? The client app compains that the origin is set to '*' even though I set it to localhost: import cors from 'cors'
export default defineNitroPlugin(({ h3App }) => {
h3App.use(
cors({
origin: 'http://localhost:3100',
credentials: true,
})
)
h3App.use(function (req, res, next) {
res.header('Access-Control-Allow-Origin', 'http://localhost:3100')
res.header('Access-Control-Allow-Credentials', true)
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
res.header(
'Access-Control-Allow-Headers',
'Origin,X-Requested-With,Content-Type,Accept,content-type,application/json'
)
next()
})
}) Any help would be appreciated. |
We can globally enable it with routing rules too: routes: {
'/**': { cors: true }
} |
Hey, is there any development on this? |
Context: nuxt/nuxt#13599
Proposal:
We probably need an h3 utility for this as well: unjs/h3#82
The text was updated successfully, but these errors were encountered: