-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
53 lines (44 loc) · 1.81 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
let express = require("express");
let app = express();
let eta = require("eta");
const router = require("./router");
const cookieParser = require("cookie-parser");
const PORT = process.env.PORT || 8000;
const mongoose = require("mongoose");
const dotenv = require("dotenv");
dotenv.config();
/**
* The 2 variables you need to set in the .env are:
* - JWT_TOKEN_SECRET
* - DANNY_PASSWORD
*/
let env = process.env.NODE_ENV || null; // check for production vs dev
env = 1;
const DB_NAME = "stocks";
const localDatabaseURL = `mongodb://127.0.0.1:27017/${DB_NAME}`;
const { DANNY_PASSWORD } = process.env;
const productionDatabaseURL = `mongodb+srv://danny:${DANNY_PASSWORD}@centralbussing.0ay5u.gcp.mongodb.net/${DB_NAME}?retryWrites=true&w=majority`;
mongoose.set("useNewUrlParser", true);
mongoose.set("useFindAndModify", false);
mongoose.set("useCreateIndex", true);
mongoose
.connect(env ? productionDatabaseURL : localDatabaseURL, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("Mongoose Connected..."))
.catch((err) => console.log(err));
// TODO: just send whole Person object to the eta file.
// TODO: Also, make middleware that checks if person is logged in and if not, sends them back to the homepage with the alert banner: Please log in before continuing.
// TODO: IN COOKIES: a person's cart is just a comma separated list of stocks they put in their cart (eg. "vti,brk-a,mstr")
app.engine("eta", eta.renderFile);
app.set("view engine", "eta");
app.set("views", "./views");
app.use(express.static("public"));
app.use(express.json()); // to support JSON-encoded bodies
app.use(express.urlencoded({ extended: true })); // to support URL-encoded bodies
app.use(cookieParser());
app.use(router);
app.listen(PORT, function () {
console.log(`listening to requests on port ${PORT}`);
});