-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.js
More file actions
82 lines (73 loc) · 2.65 KB
/
server.js
File metadata and controls
82 lines (73 loc) · 2.65 KB
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
73
74
75
76
77
78
79
80
81
82
const express = require("express");
const mongoose = require("mongoose");
const passport = require("passport");
const cors = require("cors");
const path = require("path");
const home = require("./routes/api/Home");
const user = require("./routes/api/Users");
const seats = require("./routes/api/bookTickets");
const search = require("./routes/api/SearchMovie");
const theaters = require("./routes/api/Selecttheaters");
const checkout = require("./routes/api/Checkout");
const TicketHistory = require("./routes/api/TicketHistory");
const Dijkstra = require("./routes/api/Dijkstra");
const { DB_CONNECTION_STRING } = require("./config/keys");
const app = express();
// DB connection
mongoose
.connect(DB_CONNECTION_STRING, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
})
.then(() => console.log("Connected to MongoDB.."))
.catch((error) => console.log(error));
// middlewares
mongoose.set("useCreateIndex", true);
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(cors());
app.use("/home", home);
app.use("/users", user);
app.use("/movies/theaters", theaters);
app.use("/movies/booktickets", seats);
app.use("/movies/search", search);
app.use("/movies/checkout", checkout);
app.use("/users/mytickets", TicketHistory);
app.use("/path", Dijkstra);
app.use(passport.initialize());
// Passport Config
require("./config/passport")(passport);
// serve static asset in production
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
app.get("/", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
app.get("/movies", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
app.get("/movies/search", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
app.get("/auth/signin", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
app.get("/auth/signup", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
app.get("/movies/theater", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
app.get("/movies/seats", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
app.get("/mytickets", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
}
app.get("*", (req, res) => {
res.send("404 error invalid route");
});
const port = process.env.PORT || 4000;
app.listen(port, () => console.log(`Listening on port ${port}...`));