-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
62 lines (39 loc) · 1.42 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
// Setup server, session and middleware here.
//referred professor's lecture code 8, my lab8 and professor's lecture code 10
import express from 'express';
const app = express();
import cookieParser from 'cookie-parser';
import session from 'express-session';
import configRoutes from './routes/index.js';
import { solarSelection } from './config/mongoCollections.js';
import {fileURLToPath} from 'url';
import {dirname} from 'path';
import exphbs from 'express-handlebars';
import middlewareMethods from './middleware.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const staticDir = express.static(__dirname + '/public');
app.use('/public', staticDir);
app.use(cookieParser());
app.use(express.json());
app.use(express.urlencoded({extended: true}));
// app.use(rewriteUnsupportedBrowserMethods);
app.engine('handlebars', exphbs.engine({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');
//took reference from lab10 ruberics
app.use(
session({
name: 'AuthCookie',
secret: 'some secret string!',
resave: false,
saveUninitialized: false
})
);
app.use(middlewareMethods.loggingMiddleware);
//console.log("Before app is called");
configRoutes(app);
//console.log("After app is called");
app.listen(3000, () => {
console.log("We've now got a server!");
console.log('Your routes will be running on http://localhost:3000');
});