1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- require('dotenv').config({ path: path.join(__dirname, '..', '..', '.env') })
- const express = require('express')
- const app = express()
- const path = require('node:path')
- const port = process.env.PORT
- const bodyParser = require('body-parser')
- const aws = require('aws-sdk')
- app.use(bodyParser.json())
- app.get('/', (req, res) => {
- const htmlPath = path.join(__dirname, 'public', 'index.html')
- res.sendFile(htmlPath)
- })
- app.get('/drag', (req, res) => {
- const htmlPath = path.join(__dirname, 'public', 'drag.html')
- res.sendFile(htmlPath)
- })
- app.post('/sign-s3', (req, res) => {
- const s3 = new aws.S3()
- const fileName = req.body.filename
- const { contentType } = req.body
- const s3Params = {
- Bucket: process.env.S3_BUCKET,
- Key: fileName,
- Expires: 60,
- ContentType: contentType,
- ACL: 'public-read',
- }
- s3.getSignedUrl('putObject', s3Params, (err, data) => {
- if (err) {
- console.log(err)
- return res.end()
- }
- const returnData = {
- url: data,
- method: 'PUT',
- }
- res.write(JSON.stringify(returnData))
- res.end()
- })
- })
- app.listen(port, () => {
- console.log(`Example app listening on port ${port}`)
- })
|