Skip to content

Commit 7130fe9

Browse files
committed
enable CORS
1 parent 02e843a commit 7130fe9

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@aws-sdk/util-dynamodb": "^3.624.0",
4040
"@fastify/auth": "^4.6.1",
4141
"@fastify/aws-lambda": "^4.1.0",
42+
"@fastify/cors": "^9.0.1",
4243
"fastify": "^4.28.1",
4344
"fastify-plugin": "^4.5.1",
4445
"jsonwebtoken": "^9.0.2",

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import errorHandlerPlugin from "./plugins/errorHandler.js";
88
import { RunEnvironment, runEnvironments } from "./roles.js";
99
import { InternalServerError } from "./errors/index.js";
1010
import eventsPlugin from "./routes/events.js";
11+
import cors from '@fastify/cors'
1112

1213
const now = () => Date.now();
1314

@@ -62,6 +63,10 @@ async function init() {
6263
},
6364
{ prefix: "/api/v1" },
6465
);
66+
await app.register(cors, {
67+
origin: (process.env.ValidCorsOrigins || "*").split(',')
68+
})
69+
6570
return app;
6671
}
6772

yarn.lock

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,14 @@
882882
resolved "https://registry.yarnpkg.com/@fastify/aws-lambda/-/aws-lambda-4.1.0.tgz#67dc617bbd596e078bee6e83a4ec9d31dee7686b"
883883
integrity sha512-293HSdtr4muZZi4UxjrDgddxlLRDbNxT5x/eOX78obMA1Du3tfpuP7WuyfnA4GXaeckj/soJ2jiuD2sM4VIW9Q==
884884

885+
"@fastify/cors@^9.0.1":
886+
version "9.0.1"
887+
resolved "https://registry.yarnpkg.com/@fastify/cors/-/cors-9.0.1.tgz#9ddb61b4a61e02749c5c54ca29f1c646794145be"
888+
integrity sha512-YY9Ho3ovI+QHIL2hW+9X4XqQjXLjJqsU+sMV/xFsxZkE8p3GNnYVFpoOxF7SsP5ZL76gwvbo3V9L+FIekBGU4Q==
889+
dependencies:
890+
fastify-plugin "^4.0.0"
891+
mnemonist "0.39.6"
892+
885893
"@fastify/error@^3.3.0", "@fastify/error@^3.4.0":
886894
version "3.4.1"
887895
resolved "https://registry.yarnpkg.com/@fastify/error/-/error-3.4.1.tgz#b14bb4cac3dd4ec614becbc643d1511331a6425c"
@@ -3462,6 +3470,13 @@ [email protected]:
34623470
dependencies:
34633471
obliterator "^1.6.1"
34643472

3473+
3474+
version "0.39.6"
3475+
resolved "https://registry.yarnpkg.com/mnemonist/-/mnemonist-0.39.6.tgz#0b3c9b7381d9edf6ce1957e74b25a8ad25732f57"
3476+
integrity sha512-A/0v5Z59y63US00cRSLiloEIw3t5G+MiKz4BhX21FI+YBJXBOGW0ohFxTxO08dsOYlzxo87T7vGfZKYp2bcAWA==
3477+
dependencies:
3478+
obliterator "^2.0.1"
3479+
34653480
34663481
version "2.1.2"
34673482
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
@@ -3547,6 +3562,11 @@ obliterator@^1.6.1:
35473562
resolved "https://registry.yarnpkg.com/obliterator/-/obliterator-1.6.1.tgz#dea03e8ab821f6c4d96a299e17aef6a3af994ef3"
35483563
integrity sha512-9WXswnqINnnhOG/5SLimUlzuU1hFJUc8zkwyD59Sd+dPOMf05PmnYG/d6Q7HZ+KmgkZJa1PxRso6QdM3sTNHig==
35493564

3565+
obliterator@^2.0.1:
3566+
version "2.0.4"
3567+
resolved "https://registry.yarnpkg.com/obliterator/-/obliterator-2.0.4.tgz#fa650e019b2d075d745e44f1effeb13a2adbe816"
3568+
integrity sha512-lgHwxlxV1qIg1Eap7LgIeoBWIMFibOjbrYPIPJZcI1mmGAI2m3lNYpK12Y+GBdPQ0U1hRwSord7GIaawz962qQ==
3569+
35503570
on-exit-leak-free@^2.1.0:
35513571
version "2.1.2"
35523572
resolved "https://registry.yarnpkg.com/on-exit-leak-free/-/on-exit-leak-free-2.1.2.tgz#fed195c9ebddb7d9e4c3842f93f281ac8dadd3b8"

0 commit comments

Comments
 (0)