feat(backend): Add CORS support for Capacitor app
Some checks are pending
Test / backend-test (push) Waiting to run
Test / frontend-test (push) Waiting to run

This commit is contained in:
fullsizemalt 2026-01-06 23:08:15 -08:00
parent 44f1939b2b
commit 0723c93908
3 changed files with 46 additions and 0 deletions

View file

@ -24,6 +24,7 @@
"zod": "^3.22.4" "zod": "^3.22.4"
}, },
"devDependencies": { "devDependencies": {
"@fastify/cors": "^11.2.0",
"@types/jest": "^29.5.11", "@types/jest": "^29.5.11",
"@types/node": "^20.10.0", "@types/node": "^20.10.0",
"eslint": "^8.56.0", "eslint": "^8.56.0",
@ -702,6 +703,44 @@
"integrity": "sha512-m9FVDXU3GT2ITSe0UaMA5rU3QkfC/UXtCU8y0gSN/GugTqtVldOBWIB5V6V3sbmenVZUIpU6f+mPEO2+m5iTaA==", "integrity": "sha512-m9FVDXU3GT2ITSe0UaMA5rU3QkfC/UXtCU8y0gSN/GugTqtVldOBWIB5V6V3sbmenVZUIpU6f+mPEO2+m5iTaA==",
"license": "MIT" "license": "MIT"
}, },
"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==",
"dev": true,
"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/cors/node_modules/fastify-plugin": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/fastify-plugin/-/fastify-plugin-5.1.0.tgz",
"integrity": "sha512-FAIDA8eovSt5qcDgcBvDuX/v0Cjz0ohGhENZ/wpc3y+oZCY2afZ9Baqql3g/lC+OHRnciQol4ww7tuthOb9idw==",
"dev": true,
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/fastify"
},
{
"type": "opencollective",
"url": "https://opencollective.com/fastify"
}
],
"license": "MIT"
},
"node_modules/@fastify/deepmerge": { "node_modules/@fastify/deepmerge": {
"version": "2.0.2", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/@fastify/deepmerge/-/deepmerge-2.0.2.tgz", "resolved": "https://registry.npmjs.org/@fastify/deepmerge/-/deepmerge-2.0.2.tgz",

View file

@ -32,6 +32,7 @@
"zod": "^3.22.4" "zod": "^3.22.4"
}, },
"devDependencies": { "devDependencies": {
"@fastify/cors": "^11.2.0",
"@types/jest": "^29.5.11", "@types/jest": "^29.5.11",
"@types/node": "^20.10.0", "@types/node": "^20.10.0",
"eslint": "^8.56.0", "eslint": "^8.56.0",

View file

@ -1,4 +1,5 @@
import fastify from 'fastify'; import fastify from 'fastify';
import cors from '@fastify/cors';
import jwt from '@fastify/jwt'; import jwt from '@fastify/jwt';
import dotenv from 'dotenv'; import dotenv from 'dotenv';
import { prismaPlugin } from './plugins/prisma'; import { prismaPlugin } from './plugins/prisma';
@ -33,6 +34,11 @@ const server = fastify({
}); });
// Register Plugins // Register Plugins
server.register(cors, {
origin: ['https://veridian.runfoo.run', 'http://localhost:5173'],
credentials: true,
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']
});
server.register(prismaPlugin); server.register(prismaPlugin);
server.register(jwt, { server.register(jwt, {
secret: process.env.JWT_SECRET || 'supersecret' secret: process.env.JWT_SECRET || 'supersecret'