-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.js
70 lines (48 loc) · 1.46 KB
/
main.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
69
const express = require("express"),
app = express(),
mongoose = require("mongoose"),
cors = require("cors"),
router = require("./routes/index"),
history = require('connect-history-api-fallback'),
path = require("path"),
serveStatic = require("serve-static");
app.use(express.json());
app.use(express.urlencoded());
const mongodbURI =
process.env.MONGODB_URI || "mongodb://localhost:27017/studyplan";
mongoose.connect(mongodbURI, { useNewUrlParser: true }).then(
() => {
console.log("Database is connected");
},
(err) => {
console.log("Can not connect to the database" + err);
}
);
mongoose.set("useFindAndModify", false);
app.use(history({
// OPTIONAL: Includes more verbose logging
verbose: true
}))
app.use(
express.urlencoded({
extended: true,
})
);
app.use(express.json());
// app.use(express.static("public")); //In order to use static file
app.use(cors());
// app.use(serveStatic(__dirname + "/dist"));
app.set("port", process.env.PORT || 3000);
app.set("view engine", "ejs"); //To use EJS
// Serve static assets
// app.use(express.static(path.join(__dirname, 'dist')));
// // Redirect all requests to `index.html`
// app.get('/*', (req, res) => {
// res.sendFile(path.join(__dirname, 'dist', 'index.html'));
// })
app.use(serveStatic(__dirname + '/dist'));
app.use("/", router);
app.listen(app.get("port"), () => {
console.log(`Server running at http://localhost:${app.get("port")}`);
});
module.exports = app;