Skip to content

How to enable CORS? #95

Answered by kraih
francelwebdev asked this question in Q&A
Mar 7, 2023 · 3 comments · 3 replies
Discussion options

You must be logged in to vote

If you hadn't left IRC so abruptly i would have given you a more detailed explanation than you got until then. CORS is just a bunch of headers you could set like ctx.res.set('Access-Control-Allow-Origin', '*');. Ideally you would implement CORS as router conditions in an NPM plugin. We have a bunch for Perl already, porting one of them should be very easy.

To enable CORS indiscriminately for all routes you could just add this hook to your application:

app.addContextHook('router:before', async ctx => {
 ctx.res.set('Access-Control-Allow-Origin', '*');
});

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@kraih
Comment options

kraih Mar 7, 2023
Maintainer

@jberger
Comment options

Comment options

You must be logged in to vote
1 reply
@francelwebdev
Comment options

Answer selected by kraih
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants