-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (28 loc) · 816 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require('dotenv').config()
const express = require('express')
const imageServices = require('./services/amazonS3/imageServices')
const app = express()
const port = 3000
/////////
app.use(json())
//------EXAMPLE TO USE AMAZON S3 SERVICES TO UPLOAD AND DELETE IMAGE------
//
app.post('/images', imageServices.uploadMiddleware, async (req, res) => {
try{
const urlOfImage = await imageServices.uploadImage(req.file)
res.status(200).send(urlOfImage)
} catch (error) {
res.status(500).json(error)
}
})
app.delete('/images', async (req, res) => {
try {
await imageServices.deleteImage(req.body.url)
res.status(204).end()
} catch (error) {
res.status(500).json(error)
}
})
app.listen(port, () => {
console.log(`Server is running on ${port}`)
})