-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
46 lines (36 loc) · 984 Bytes
/
Copy pathapp.js
File metadata and controls
46 lines (36 loc) · 984 Bytes
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
/* eslint-disable func-names */
/* eslint-disable require-yield */
const Koa = require("koa");
const helmet = require("koa-helmet");
const koaBody = require("koa-body");
const logger = require("koa-logger");
const cors = require("koa-cors");
const routes = require("./routes/index");
const orm = require("./models");
const app = new Koa();
app.keys = [
"these secret keys are used to sign HTTP cookies",
"to make sure only this app can generate a valid one",
"and thus preventing someone just writing a cookie",
"saying he is logged in when it's really not"
];
// expose ORM through context's prototype
app.context.orm = orm;
/**
* Middlewares
*/
// basic security middleware
app.use(helmet());
// HTTP request body parser
app.use(koaBody());
// HTTP request logger
app.use(logger());
// Cors
const options = {
origin: "*",
methods: "GET, PUT, POST, PATCH, DELETE, OPTIONS"
};
app.use(cors(options));
// routing
app.use(routes.routes());
module.exports = app;