generated from nhcarrigan/template
fix: cors logic
All checks were successful
Node.js CI / Lint and Test (pull_request) Successful in 1m10s
All checks were successful
Node.js CI / Lint and Test (pull_request) Successful in 1m10s
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import { routesWithoutCors } from "../config/routesWithoutCors.js";
|
||||
import type { onRequestHookHandler } from "fastify";
|
||||
|
||||
const isValidOrigin = (origin: string | undefined): boolean => {
|
||||
@ -27,7 +28,7 @@ const isValidOrigin = (origin: string | undefined): boolean => {
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises -- For reasons I cannot comprehend, Fastify seems to require us to return a request?
|
||||
export const corsHook: onRequestHookHandler = async(request, response) => {
|
||||
if (!request.url.startsWith("/submit")) {
|
||||
if (routesWithoutCors.includes(request.url)) {
|
||||
return undefined;
|
||||
}
|
||||
if (!isValidOrigin(request.headers.origin)) {
|
||||
|
Reference in New Issue
Block a user