-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
63 lines (55 loc) · 1.55 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
require("dotenv").config();
require("./config/connection");
require("./config/authStrategy");
//Set Up
const express = require("express");
const morgan = require("morgan");
const path = require("node:path");
const cors = require("cors");
const helmet = require("helmet");
const session = require("express-session");
const passport = require("passport");
const app = express();
const PORT = process.env.PORT || 3000;
//Declare routing variables
const siteRoutes = require("./routes/siteRouter");
const trackerRoutes = require("./routes/trackerRouter");
const authRoutes = require("./routes/authRouter");
//Use Middleware
app.use(
helmet({
contentSecurityPolicy: false,
})
);
app.use(cors());
app.use(morgan("dev"));
app.use(express.static(path.join(__dirname, "public")));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
//Use session and passport
app.use(
session({
secret: process.env.SECRET_KEY,
resave: false,
saveUninitialized: false,
})
);
app.use(passport.initialize());
app.use(passport.session());
//making a route for home page(index.html)
app.get("/", (req, res, next) => {
res
.status(200)
.json({ success: { message: "This is the homepage" }, statusCode: 200 });
});
//use the routes in the specified router files
app.use("/api", siteRoutes);
app.use("/financial", trackerRoutes);
app.use("/auth", authRoutes);
//Server
app.listen(PORT, () => {
//to listen for requests
console.log(`The server is listening at port ${PORT}`);
//to get the localhost link
console.log(`http://localhost:${PORT}`);
});