-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
54 lines (46 loc) · 1.37 KB
/
index.js
File metadata and controls
54 lines (46 loc) · 1.37 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
const restify = require('restify');
const corsMiddleware = require('restify-cors-middleware');
const chalk = require('chalk');
const printf = require('printf');
const models = require('./models');
const cors = corsMiddleware({
preflightMaxAge: 5, // Optional
origins: [
/^http:\/\/localhost(:[\d]+)?$/,
'https://*.netlify.app',
'https://member.commonsstack.foundation',
// "https://myapp.com" // Add endpoint here...
],
allowHeaders: ['sessionid'],
});
const server = restify.createServer({
name: 'API',
version: '1.0.0',
});
server.use(restify.plugins.acceptParser(server.acceptable));
server.use(restify.plugins.queryParser());
server.use(restify.plugins.bodyParser());
server.pre(cors.preflight);
server.use(cors.actual);
// attach routes
require('./routes-signature')(server);
require('./routes-balance')(server);
// eslint-disable-next-line no-unused-vars
server.get('/ping', function (req, res, next) {
return res.send(200);
});
const listAllRoutes = (s) => {
Object.entries(s.router.getRoutes())
.sort((a, b) => {
return a[1].path.localeCompare(b[1].path);
})
.forEach((route) => {
console.log(chalk.yellow(printf('%*s', route[1].method, 6)), route[1].path);
});
};
models.init().then(() => {
server.listen(5005, function () {
listAllRoutes(server);
console.log('%s listening at %s', server.name, server.url);
});
});