-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
33 lines (27 loc) · 953 Bytes
/
index.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
/**
* Entry point for the api server.
*
* Configured with micro-router enabling the api server to serve to specific endpoints
*/
const microCors = require('micro-cors');
const { router, get } = require('microrouter');
const { api } = require('./src');
/**
* Set up cors for the allowed methods and allowed headers, etc.
* These are the defaults used by the package micro-cors
*/
const cors = microCors({
allowMethods: ['POST', 'GET', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
allowHeaders: ['X-Requested-With', 'Access-Control-Allow-Origin', 'X-HTTP-Method-Override', 'Content-Type', 'Authorization', 'Accept'],
allowCredentials: true,
exposeHeaders: [],
maxAge: 86400,
origin: '*',
});
module.exports = cors(router(
// responds to the ping events. Typically for health-checks
get('/ping', api.ping),
// Add your api endpoints here
// returns the not found api if the end point is not found
get('/*', api.notFound),
));