config.enableCorsForAllOrigins() is not adding proper CORS headers
See original GitHub issueActual behavior (the bug) Http header “access-control-allow-origin:*” is not being added to responses
Expected behavior header should be present on all responses
To Reproduce
Javalin.create().apply {
config.contextPath = "/"
config.enableCorsForAllOrigins()
config.enableDevLogging()
get("/") { ctx -> ctx.html("test") }
}.start(80)
Workaround I needed to use in order to get the CORS header in all requests is this:
Javalin.create().apply {
config.contextPath = "/"
config.enableCorsForAllOrigins()
config.enableDevLogging()
before { ctx ->
ctx.header(Header.ACCESS_CONTROL_ALLOW_ORIGIN, "*")
}
get("/") { ctx -> ctx.html("test") }
}.start(80)
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
config.enableCorsForAllOrigins() is not adding proper CORS ...
Actual behavior (the bug) Http header "access-control-allow-origin:*" is not being added to responses Expected behavior header should be ...
Read more >Why doesn't adding CORS headers to an OPTIONS route ...
I found the easiest way is to use the node.js package cors. The simplest usage is: var cors = require('cors') var app =...
Read more >CORS Enabled - W3C Wiki
Granting JavaScript clients basic access to your resources simply requires adding one HTTP Response Header, namely: Access-Control-Allow-Origin: ...
Read more >Handling CORS | Socket.IO
Handling CORS. Configuration. Since Socket.IO v3, you need to explicitly enable Cross-Origin Resource Sharing (CORS).
Read more >javalin-io/general - Gitter
enableCorsForAllOrigins (); config.requestLogger((ctx, ms) -> { if (ctx.req.getAttribute("handled-as-static-file") == null) { // if the request is not for a ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
alright, the correct way to apply it was
now it works
FYI the way this sneakily substitutes
*
with theOrigin
header value breaks external caches that weren’t configured for this behavior. A cached response from one origin may be sent to another requests with a different origin.