-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
59 lines (50 loc) · 1.76 KB
/
app.js
File metadata and controls
59 lines (50 loc) · 1.76 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
if (process.env.NODE_ENV !== 'production') require('dotenv').config()
const createError = require('http-errors')
const express = require('express')
const app = express()
const path = require('path')
app.use(express.json())
app.use(express.static(path.join(__dirname, 'public')))
const cloudinary = require('cloudinary').v2
// Configure your cloud name, API key and API secret:
cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET,
secure: true
})
// Upload signing API (using this API should require authentication)
app.get('/api/signuploadwidget', (req, res, next) => {
// Timestamp and cloudinary utility function used to sign an Upload Widget upload.
const timestamp = Date.now()
const signature = cloudinary.utils.api_sign_request(
{
timestamp: timestamp,
source: 'uw',
folder: 'signed_upload_demo_uw'
},
cloudinary.config().api_secret
)
res.json({
signature: signature,
timestamp: timestamp,
cloudname: cloudinary.config().cloud_name,
apikey: cloudinary.config().api_key,
})
})
// catch 404 and forward to error handler
app.use(function (req, res, next) {
next(createError(404))
})
// error handler
app.use(function (err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message
res.locals.error = req.app.get('env') === 'development' ? err : {}
// send error to frontend
res.status(err.status || 500).send(err.message)
})
// module.exports = app
const port = process.env.PORT || 3000
const host = process.env.HOST || 'localhost'
app.listen(port, () => console.info(`Server is up on http://${host}:${port}`))