-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (35 loc) · 1.19 KB
/
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
41
42
43
44
45
require("dotenv").config();
const express = require("express");
const winston = require("winston");
const helmet = require("helmet");
const cors = require("cors");
const path = require("path");
const ms = require('ms');
const { getLatestBooks, searchImages } = require("./controllers");
const app = express();
const port = process.env.PORT;
const staticOptions = { maxAge: ms('10d') };
const corsOptions = { methods: 'GET' }
app.use(helmet());
app.use(helmet.contentSecurityPolicy({
directives: {
defaultSrc: ["'self'"],
styleSrc: ["'self'", 'https://fonts.googleapis.com'],
fontSrc: ['https://fonts.gstatic.com'],
formAction: ["'self'"],
frameAncestors: ["'none'"]
}
}));
app.use(helmet.referrerPolicy({policy: 'same-origin'}));
app.use(express.static(path.join(__dirname, "public"), staticOptions));
app.use(cors(corsOptions));
// GET - log of previous 10 search queries
app.get("/api/latest/imagesearch", getLatestBooks);
// GET - results of custom image search of imgur
app.get("/api/imagesearch/?", searchImages);
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
})
app.listen(port, () => {
winston.log("info", `Listening on PORT ${port}`);
});