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,9 +45,16 @@ export default class Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mainMiddleware = async (req, res, next) => {
|
mainMiddleware = async (req, res, next) => {
|
||||||
|
if (this.server.params.bypassCors === true) {
|
||||||
if (req.method === "OPTIONS") {
|
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()
|
return res.status(204).end()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// register body parser
|
// register body parser
|
||||||
if (req.headers["content-type"]) {
|
if (req.headers["content-type"]) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user