-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
28 lines (23 loc) · 959 Bytes
/
server.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
const ex = require('express');
const { fileMetadataRouter } = require('./routes/file-metadata');
const { validateAuthToken, handleError, enableCors, allowOperation } = require('./middleware');
const { stripeRouter } = require('./routes/stripeRouter');
const server = ex();
// logging middleware
server.use((req, res, next) => {
console.log(req.method, req.originalUrl, req.headers.referer, req.headers.body)
next();
})
// remove top level ex.json() so that we get raw json on the stripe route, include in each route
// server.use(ex.json());
server.use(ex.urlencoded({ extended: true }));
server.use(enableCors)
// routers
server.use('/api/file-metadata', validateAuthToken, ex.json(), fileMetadataRouter)
server.use('/stripe', stripeRouter)
server.get('/authorized-to-read', validateAuthToken, allowOperation(['read:files']), (req, res) => {
res.status(200).send('Resources sent!')});
server.use(handleError);
module.exports = {
server
}