mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-10-17 05:14:19 +02:00
origin: ['*'] in config/cors.ts never matches a real Origin header, since @adonisjs/cors only treats '*' as a wildcard when it's the bare string, not inside an array. So no Access-Control-Allow-Origin is ever sent, on any route, blocking any other app from reading NOMAD's map tiles cross-origin. Add a middleware scoped to the four map asset path prefixes instead of widening the global config, which would also expose the write API since credentials: true is already set there. Registered before @adonisjs/cors so it can answer OPTIONS preflights on map paths itself; the built-in middleware ends any preflight it can't match an origin for before this one would otherwise run.
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
/*
|
|
|--------------------------------------------------------------------------
|
|
| HTTP kernel file
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| The HTTP kernel file is used to register the middleware with the server
|
|
| or the router.
|
|
|
|
|
*/
|
|
|
|
import router from '@adonisjs/core/services/router'
|
|
import server from '@adonisjs/core/services/server'
|
|
|
|
/**
|
|
* The error handler is used to convert an exception
|
|
* to an HTTP response.
|
|
*/
|
|
server.errorHandler(() => import('#exceptions/handler'))
|
|
|
|
/**
|
|
* The server middleware stack runs middleware on all the HTTP
|
|
* requests, even if there is no route registered for
|
|
* the request URL.
|
|
*/
|
|
server.use([
|
|
() => import('#middleware/container_bindings_middleware'),
|
|
// Must precede @adonisjs/cors: it ends unmatched-origin preflights (#endPreFlight)
|
|
// before this middleware would ever see them, since origin: ['*'] never matches.
|
|
() => import('#middleware/maps_cors_middleware'),
|
|
() => import('@adonisjs/cors/cors_middleware'),
|
|
() => import('@adonisjs/vite/vite_middleware'),
|
|
() => import('@adonisjs/inertia/inertia_middleware'),
|
|
() => import('@adonisjs/static/static_middleware'),
|
|
() => import('#middleware/maps_static_middleware')
|
|
])
|
|
|
|
/**
|
|
* The router middleware stack runs middleware on all the HTTP
|
|
* requests with a registered route.
|
|
*/
|
|
router.use([
|
|
() => import('@adonisjs/core/bodyparser_middleware'),
|
|
// () => import('@adonisjs/session/session_middleware'),
|
|
() => import('@adonisjs/shield/shield_middleware'),
|
|
() => import('#middleware/compression_middleware'),
|
|
])
|
|
|
|
/**
|
|
* Named middleware collection must be explicitly assigned to
|
|
* the routes or the routes group.
|
|
*/
|
|
export const middleware = router.named({})
|