Skip to content

Commit

Permalink
♻️➕ fastify-cors
Browse files Browse the repository at this point in the history
  • Loading branch information
ky-is committed Sep 8, 2021
1 parent ddea3c2 commit 40dc46c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 49 deletions.
9 changes: 5 additions & 4 deletions package.json
Expand Up @@ -14,18 +14,19 @@
"dependencies": {
"esm-seedrandom": "3.0.5",
"fastify": "^3.21.0",
"fastify-cors": "^6.0.2",
"postgres": "^2.0.0-beta.8",
"socket.io": "^4.2.0",
"vue": "^3.2.10"
},
"devDependencies": {
"@ky-is/eslint-config": "^2.3.6",
"@tailwindcss/forms": "^0.3.3",
"@types/node": "^16.7.13",
"@types/node": "^16.9.0",
"@types/seedrandom": "^3.0.1",
"@typescript-eslint/eslint-plugin": "^4.31.0",
"@typescript-eslint/parser": "^4.31.0",
"@vitejs/plugin-vue": "^1.6.1",
"@vitejs/plugin-vue": "^1.6.2",
"@vue/compiler-sfc": "^3.2.10",
"@vue/eslint-config-typescript": "^7.0.0",
"autoprefixer": "^10.3.4",
Expand All @@ -34,9 +35,9 @@
"fs-extra": "^10.0.0",
"postcss": "^8.3.6",
"socket.io-client": "^4.2.0",
"tailwindcss": "^2.2.11",
"tailwindcss": "^2.2.14",
"typescript": "^4.4.2",
"vite": "^2.5.4",
"vite": "^2.5.6",
"vue-router": "^4.0.11"
},
"eslintConfig": {
Expand Down
86 changes: 45 additions & 41 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions server/index.ts
@@ -1,4 +1,5 @@
import Fastify from 'fastify'
import FastifyCORS from 'fastify-cors'

import { TESTING } from '#c/utils.js'

Expand All @@ -14,6 +15,9 @@ const fastify = Fastify({
})

fastify
.register(FastifyCORS, {
origin: clientURL,
})
.setErrorHandler((error, request, reply) => {
if (error instanceof APIError) {
reply.statusCode = 400
Expand All @@ -22,10 +26,6 @@ fastify
throw error
}
})
.addHook('onRequest', (request, reply, next) => {
reply.header('Access-Control-Allow-Origin', clientURL)
next()
})
.after(() => {
useUserRoutes(fastify)
})
Expand Down

0 comments on commit 40dc46c

Please sign in to comment.