mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 10:34:17 +00:00
Refactor OPTIONS handling for conditional CORS bypass
OPTIONS requests are now only handled by this middleware if `bypassCors` is true, in which case permissive CORS headers are added. If `bypassCors` is false, OPTIONS requests will proceed to subsequent middleware instead of returning an empty 204 response.
This commit is contained in:
parent
fa61273d5b
commit
23ec6f215c
@ -45,8 +45,15 @@ export default class Engine {
|
||||
}
|
||||
|
||||
mainMiddleware = async (req, res, next) => {
|
||||
if (req.method === "OPTIONS") {
|
||||
return res.status(204).end()
|
||||
if (this.server.params.bypassCors === true) {
|
||||
if (req.method === "OPTIONS") {
|
||||
res.setHeader("Access-Control-Allow-Origin", "*")
|
||||
res.setHeader("Access-Control-Allow-Methods", "*")
|
||||
res.setHeader("Access-Control-Allow-Headers", "*")
|
||||
res.setHeader("Access-Control-Allow-Credentials", "true")
|
||||
|
||||
return res.status(204).end()
|
||||
}
|
||||
}
|
||||
|
||||
// register body parser
|
||||
|
Loading…
x
Reference in New Issue
Block a user