forked from komlraj/Edium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
61 lines (48 loc) · 1.44 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const express = require("express");
const session = require("express-session");
const app = express();
const mongoose = require("mongoose");
const MongoStore = require("connect-mongo")(session);
const bodyParser = require("body-parser");
const cors = require("cors");
const path = require("path");
const port = 8000;
mongoose.connect(
"mongodb://localhost/edium",
{ useNewUrlParser: true },
function(err, connection) {
if (err) throw err;
else console.log("connected to mongodb");
}
);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, "public")));
app.set("views", path.join(__dirname, "./server/views"));
app.set("view engine", "ejs");
app.use(
session({
secret: "edium",
resave: true,
saveUninitialized: true,
store: new MongoStore({ url: "mongodb://localhost/edium" })
})
);
if (process.env.NODE_ENV === "development") {
var webpack = require("webpack");
var webpackConfig = require("./webpack.config");
var compiler = webpack(webpackConfig);
app.use(
require("webpack-dev-middleware")(compiler, {
noInfo: true,
publicPath: webpackConfig.output.publicPath
})
);
app.use(require("webpack-hot-middleware")(compiler));
}
app.use(cors());
app.use("/api", require("./server/routes/api"));
app.use(require("./server/routes/index"));
app.listen(port, () => {
console.log(`server is running on http://localhost:${port}`);
});