-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·72 lines (60 loc) · 1.91 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
62
63
64
65
66
67
68
69
70
71
72
require('dotenv').config();
const express = require("express");
// fevicon icon npm package
var favicon = require('serve-favicon');
// session authentication packages
// const session = require("express-session");
// const MongoStore = require("connect-mongo")(session);
const app = express();
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const cors = require("cors");
const path = require("path");
var passport = require('passport');
const port = 8000;
require('./server/models/User');
mongoose.connect(
"mongodb://localhost/travelInfo",
{ useNewUrlParser: true },
function(err, connection) {
if (err) throw err;
else console.log("connected to mongodb");
}
)
app.use(express.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(passport.initialize());
app.use(express.static(path.join(__dirname, "public")));
app.set("views", path.join(__dirname, "./server/views"));
app.set("view engine", "ejs");
// code for session based authentication
// app.use(
// session({
// secret: "travelInfo",
// resave: true,
// saveUninitialized: true,
// store: new MongoStore({ url: "mongodb://localhost/travelInfo" })
// })
// );
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(favicon( __dirname + '/assets/favicon.png'));
app.use(cors());
app.use("/api/v1", require("./server/routes/api"));
app.use("/auth", require("./server/routes/auth"));
app.use('/*', require("./server/routes/index"));
// app.use("/admin", require("./server/routes/admin"));
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});