-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (26 loc) · 900 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
34
const express = require("express");
const path = require("path");
const bodyParser = require("body-parser");
const { databaseConnect } = require("./server/db");
const { search, feed } = require("./server/routers");
if (process.env.NODE_ENV !== "production") {
require("dotenv").config({ path: ".env" });
}
const app = express();
databaseConnect();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, "client/build")));
app.use(bodyParser.json());
app.use(function (req, res, next) {
if (req.headers.host === process.env.HOST) {
res.setHeader("Access-Control-Allow-Origin", process.env.HOST);
next();
} else {
res.send("Connection refused");
}
});
app.get("/feed", feed);
app.use("/api/search", search);
const port = process.env.PORT || 5000;
module.exports = app.listen(port);
console.debug("App is listening on port " + port);