-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (26 loc) · 861 Bytes
/
server.js
File metadata and controls
35 lines (26 loc) · 861 Bytes
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
35
require('dotenv').config()
const express = require('express')
const cloudinary = require('cloudinary')
const formData = require('express-form-data')
const cors = require('cors')
const { CLIENT_ORIGIN } = require('./config')
const app = express()
cloudinary.config({
cloud_name: process.env.CLOUD_NAME,
api_key: process.env.API_KEY,
api_secret: process.env.API_SECRET
})
app.use(cors({
origin: CLIENT_ORIGIN
}))
app.use(formData.parse())
app.get('/wake-up', (req, res) => res.send('👌'))
app.post('/image-upload', (req, res) => {
const values = Object.values(req.files)
const promises = values.map(image => cloudinary.uploader.upload(image.path))
Promise
.all(promises)
.then(results => res.json(results))
.catch((err) => res.status(400).json(err))
})
app.listen(process.env.PORT || 8080, () => console.log('👍'))