-
Notifications
You must be signed in to change notification settings - Fork 0
/
heroku.js
43 lines (38 loc) · 1.08 KB
/
heroku.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
35
36
37
38
39
40
41
42
43
const PORT = process.env.PORT || 8080;
const express = require('express');
const bodyParser = require('body-parser');
const router = express.Router();
const app = express();
const dynos = {
'facebook-publish': require('./dynos/facebook-publish.js')
};
const validateMiddleware = (req, res, next) => {
if (req.query.token !== process.env.token) {
const errMsgToken = 'No token.';
res.status(400).send(errMsgToken);
return next(errMsgToken);
}
const errMsgDyno = 'No dyno provided.';
if (!req.params.dyno) {
res.status(400).send(errMsgDyno);
return next(errMsgDyno);
}
const dyno = dynos[req.params.dyno];
if (!dyno) {
res.status(400).send(errMsgDyno);
return next(errMsgDyno);
}
req.dyno = dyno;
return next();
};
router
.all('/', function(req, res) {
req.dyno({
secrets: process.env
}, req, res);
});
app
.use(bodyParser.json())
.use('/:dyno', validateMiddleware, router)
.listen(PORT, () => console.log(`Listening on ${ PORT }`));
module.exports = app;