Skip to content

Commit

Permalink
Merge pull request #16 from aarontravass:aaron/platform
Browse files Browse the repository at this point in the history
fix: added cors for upload server
  • Loading branch information
aarontravass authored Jul 13, 2024
2 parents 66e0f05 + 0500d56 commit 35ca745
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 44 deletions.
27 changes: 0 additions & 27 deletions .github/workflows/main.yml

This file was deleted.

1 change: 1 addition & 0 deletions packages/upload/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"dependencies": {
"@aws-sdk/client-s3": "3.47.0",
"@fastify/cors": "^9.0.1",
"@fastify/multipart": "^8.3.0",
"@medihacks/prisma": "workspace:^",
"fastify": "^4.28.1"
Expand Down
3 changes: 1 addition & 2 deletions packages/upload/src/filebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export const uploadFile = async ({ file, user }: { file: MultipartFile; user: Us
Bucket: user.id,
ContentType: file.mimetype
})
const out = await headObject({ fileName: file.filename, bucketName: user.id })
return out
return headObject({ fileName: file.filename, bucketName: user.id })
}

export const headObject = ({ bucketName, fileName }: { bucketName: string; fileName: string }) =>
Expand Down
5 changes: 5 additions & 0 deletions packages/upload/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ import FastifyMultipart from '@fastify/multipart'
import { isTokenValid } from './utils'
import { uploadFile } from './filebase'
import { prisma } from './prisma'
import FastifyCors from '@fastify/cors'

const fastify = Fastify({
logger: true
})
fastify.register(FastifyMultipart)
await fastify.register(FastifyCors, {
origin: true,
methods: ['POST']
})

fastify.post('/upload', async (req, res) => {
const token = (req.query as Record<string, string>).token
Expand Down
38 changes: 23 additions & 15 deletions pnpm-lock.yaml

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

0 comments on commit 35ca745

Please sign in to comment.