-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
28 lines (20 loc) · 806 Bytes
/
app.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 express = require("express"),
bodyParser = require("body-parser"),
cors = require("cors"),
morgan = require("morgan"),
apicache = require("apicache")
const pingRouter = require("./routes/api/ping"),
postsRouter = require("./routes/api/posts");
const app = express();
app.use(cors({origin: "*"}));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(morgan("dev")); // logging requests
const acache = apicache.middleware; // caching
app.get("/api/ping", acache("45 minutes"), pingRouter);
app.get("/api/posts", acache("45 minutes"), postsRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
res.status(404).json("Page Not Found");
});
module.exports = app;