Skip to content

Commit

Permalink
feat: upgrade server to fastify v5 (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
thezzisu authored Dec 28, 2024
1 parent bb51026 commit da2c5da
Show file tree
Hide file tree
Showing 9 changed files with 367 additions and 253 deletions.
2 changes: 2 additions & 0 deletions .yarn/versions/621cf1da.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
releases:
"@aoi-js/server": patch
18 changes: 9 additions & 9 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
"@aoi-js/rule": "workspace:^",
"@aws-sdk/client-s3": "^3.385.0",
"@aws-sdk/s3-request-presigner": "^3.385.0",
"@fastify/formbody": "^7.4.0",
"@fastify/jwt": "^7.2.0",
"@fastify/rate-limit": "^9.1.0",
"@fastify/sensible": "^5.2.0",
"@fastify/type-provider-typebox": "^4.0.0",
"@fastify/formbody": "^8.0.1",
"@fastify/jwt": "^9.0.2",
"@fastify/rate-limit": "^10.2.1",
"@fastify/sensible": "^6.0.2",
"@fastify/type-provider-typebox": "^5.1.0",
"@lcpu/iaaa": "^1.0.0",
"@sinclair/typebox": "^0.32.19",
"@types/nodemailer": "^6.4.14",
"bcrypt": "^5.1.1",
"fastify": "^4.25.1",
"fastify-plugin": "^4.5.1",
"fastify": "^5.2.0",
"fastify-plugin": "^5.0.1",
"ioredis": "^5.3.2",
"mongodb": "^6.3.0",
"nodemailer": "^6.9.11",
Expand All @@ -49,8 +49,8 @@
"pino-pretty": "^10.3.0"
},
"optionalDependencies": {
"@fastify/swagger": "^8.12.1",
"@fastify/swagger-ui": "^3.0.0"
"@fastify/swagger": "^9.4.0",
"@fastify/swagger-ui": "^5.2.0"
},
"scripts": {
"build": "run -T tsc",
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function decoratedVerifyMfa(this: FastifyRequest, token: string): string {
}

export const apiRoutes = defineRoutes(async (s) => {
s.decorateRequest('_container', null)
s.decorateRequest('_container')
s.decorateRequest('provide', decoratedProvide)
s.decorateRequest('inject', decoratedInject)
s.decorateRequest('loadMembership', decoratedLoadMembership)
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/routes/oauth/iaaaCompat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const oauthIaaaCompatRoutes = defineRoutes(async (s) => {
const params = new URLSearchParams()
params.set('client_id', req.body.appID)
params.set('redirect_uri', req.body.redirectUrl)
return rep.redirect(302, '/oauth/authorize' + '?' + params.toString())
return rep.redirect('/oauth/authorize' + '?' + params.toString(), 302)
}
)

Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/routes/plugins/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export const apiUserAuthPlugin = fastifyPlugin(async (s) => {
// Only allow tagged routes
if (req.user.tags) {
const tags = new Set(req.user.tags)
if (!req.routeOptions.schema.tags?.some((tag) => tags.has(tag))) return rep.forbidden()
if (!req.routeOptions.schema?.tags?.some((tag) => tags.has(tag))) return rep.forbidden()
}
}

// Check JWT
const { security } = req.routeOptions.schema
const security = req.routeOptions.schema?.security
if (!security || security.some((sec) => Object.hasOwn(sec, 'bearerAuth'))) {
if (!req.user) return rep.forbidden()
}
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/routes/runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const runnerRoutes = defineRoutes(async (s) => {

s.addHook('onRequest', async (req, rep) => {
// Skip register route
if (!req.routeOptions.schema.security?.length) return
if (!req.routeOptions.schema?.security?.length) return
const runnerId = loadUUID(req.headers, 'x-aoi-runner-id', s.httpErrors.unauthorized())
const runner = await runners.findOne({ _id: runnerId })
if (!runner) throw s.httpErrors.unauthorized()
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if (trustProxy) {
}

const server = fastify({
logger,
loggerInstance: logger,
trustProxy
})

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aoi-js/workspace",
"packageManager": "yarn@4.1.1",
"packageManager": "yarn@4.5.3",
"license": "AGPL-3.0-only",
"private": true,
"workspaces": [
Expand Down
Loading

0 comments on commit da2c5da

Please sign in to comment.