-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
68 lines (58 loc) · 1.95 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const express = require("express");
const mongoose = require("mongoose");
const path = require("path");
const cors = require("cors");
const cookieModel = require("./models/cookie");
const cookieData = require("./data/cookies");
const app = express();
require("dotenv").config();
// Bodyparser middleware
app.use(express.json());
app.use(cors());
// DB config
const db = process.env.MONGODB_URL || "mongodb://localhost/webevaluator";
// connect to mongo
mongoose
.connect(db, {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => console.log("Mongoose connected with db", db))
.then(() => cookieModel.countDocuments())
.then(count => {
if (!count) {
return cookieModel.insertMany(cookieData);
}
})
.catch((err) => console.log(err));
var morgan = require('morgan')
var rfs = require('rotating-file-stream') // version 2.x
// create a rotating write stream
var accessLogStream = rfs.createStream('access.log', {
interval: '1d', // rotate daily
path: path.join(__dirname, './logs')
})
// setup the logger
app.use(morgan('combined', { stream: accessLogStream }))
// app.get('/', function (req, res) {
// res.send('hello, world!')
// })
// use routes
app.use("/api/status", require("./routes/status"));
app.use("/api/errors", require("./routes/errors"));
app.use("/api/cchecker", require("./routes/cookie"));
app.use("/api/screenshot", require("./routes/screenshot"));
app.use("/api/sniffer", require("./routes/sniffer"));
app.use("/api/pdf", require("./routes/pdf"));
// serve static assets if we are in production
if (process.env.NODE_ENV === "production") {
// set static folder
app.use(express.static("client/build"));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
} else {
app.use(express.static("public"));
}
const port = process.env.PORT || 5000;
app.listen(port, () => console.log(`server started on port ${port} on ${process.env.NODE_ENV} environment`));