-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
40 lines (30 loc) · 959 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
29
30
31
32
33
34
35
36
37
38
39
40
const express = require("express");
const helmet = require("helmet");
const xss = require("xss-clean");
const compression = require("compression");
const cors = require("cors");
const { getAllNews, getSingleNews, getNewsByType } = require("./controllers/blog.controller");
require("dotenv/config");
const app = express();
const router = express.Router();
// set security HTTP headers
app.use(helmet());
// parse json request body
app.use(express.json());
// parse urlencoded request body
app.use(express.urlencoded({ extended: true }));
// sanitize request data
app.use(xss());
// gzip compression
app.use(compression());
// enable cors
app.use(cors());
app.options("*", cors());
app.use("/api/v1", router);
router.get("/", (req, res) => {
return res.status(200).json({ message: "Blog Mock API" });
});
router.get("/news", getAllNews);
router.get("/news/:slug", getSingleNews);
router.get("/news/type/:type", getNewsByType);
module.exports = app;