add cors handling

This commit is contained in:
Darius
2026-02-06 00:00:31 +01:00
parent 34fee498eb
commit 57bbae2919
3 changed files with 29 additions and 0 deletions

21
package-lock.json generated
View File

@@ -9,6 +9,7 @@
"version": "1.0.0",
"dependencies": {
"@dpu/shared": "git+https://git.dariusbag.dev/DarDarBinks/dpu-shared.git",
"@fastify/cors": "^11.2.0",
"@fastify/sse": "^0.4.0",
"@fastify/swagger": "^9.6.1",
"@fastify/swagger-ui": "^5.2.3",
@@ -516,6 +517,26 @@
"fast-uri": "^3.0.0"
}
},
"node_modules/@fastify/cors": {
"version": "11.2.0",
"resolved": "https://registry.npmjs.org/@fastify/cors/-/cors-11.2.0.tgz",
"integrity": "sha512-LbLHBuSAdGdSFZYTLVA3+Ch2t+sA6nq3Ejc6XLAKiQ6ViS2qFnvicpj0htsx03FyYeLs04HfRNBsz/a8SvbcUw==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/fastify"
},
{
"type": "opencollective",
"url": "https://opencollective.com/fastify"
}
],
"license": "MIT",
"dependencies": {
"fastify-plugin": "^5.0.0",
"toad-cache": "^3.7.0"
}
},
"node_modules/@fastify/error": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/@fastify/error/-/error-4.2.0.tgz",

View File

@@ -14,6 +14,7 @@
"type": "module",
"dependencies": {
"@dpu/shared": "git+https://git.dariusbag.dev/DarDarBinks/dpu-shared.git",
"@fastify/cors": "^11.2.0",
"@fastify/sse": "^0.4.0",
"@fastify/swagger": "^9.6.1",
"@fastify/swagger-ui": "^5.2.3",

View File

@@ -24,12 +24,19 @@ import { SseService } from "@dpu/shared";
import { HomepageService } from "./homepage/service.js";
import { homepageRoutes } from "./homepage/routes.js";
import fastifySSE from "@fastify/sse";
import fastifyCors from "@fastify/cors";
const fastify = Fastify().withTypeProvider<ZodTypeProvider>();
fastify.setValidatorCompiler(validatorCompiler);
fastify.setSerializerCompiler(serializerCompiler);
await fastify.register(fastifyCors, {
origin: ["http://localhost:4321", "https://dariusbag.dev"],
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
allowedHeaders: ["Content-Type", "Authorization"],
});
await fastify.register(fastifySwagger, {
openapi: {
info: {