forked from nwilseystarr/con-do
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
90 lines (75 loc) · 2.28 KB
/
server.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
73
74
75
76
77
78
79
80
81
82
83
84
85
const express = require("express");
const path = require("path");
const session = require("express-session");
// Our passport implementation
const passport = require("./server/db/config/passport")
// PORT and Models
const PORT = process.env.PORT || 3001;
const db = require("./server/db/db");
const models = require("./server/db/models/")
// Routes
const routes = require("./server/routes");
let app = express();
// Serve up static assets (usually on heroku)
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
const bodyParser = require('body-parser');
app.use(express.json());
//allowing our server to keep track of the user's auth status with session
app.use(session({ secret: "keyboard cat", resave: true, saveUninitialized: true}));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(passport.initialize());
app.use(passport.session());
app.use(routes);
// require("./attendanceRoutes/apiRoutes")(app);
// require("./attendanceRoutes/htmlRoutes")(app);
const admin = {
email: "[email protected]",
password: "password",
name: "admin account",
userType: "admin",
firstLog: false
}
const advisor = {
email: "[email protected]",
password: "password",
name: "advisor account",
userType: "advisor",
firstLog: false,
// schoolId: 99,
}
const staff = {
email: "[email protected]",
password: "password",
name: "staff account",
userType: "staff",
firstLog: false,
// committeeId: 99,
}
const delegate = {
email: "[email protected]",
password: "password",
name: "delegate account",
userType: "delegate",
firstLog: false,
// schoolId: 99,
// committeeId: 99,
// country: "none"
}
db.sync({ force: false}).then(function () {
models.User.create(admin).catch(err=> console.log(err))
models.User.create(advisor).catch(err=> console.log(err))
models.User.create(staff).catch(err=> console.log(err))
models.User.create(delegate).catch(err=> console.log(err))
models.School.create({name: "None"})
models.Committee.create({name: "None"})
app.listen(PORT, function () {
console.log(`🌎 ==> API server now on port ${PORT}!`);
});
});
// Send every request to the React app
// Define any API routes before this runs
app.get("*", function(req, res) {
res.sendFile(path.join(__dirname, "./client/build/index.html"));
});