-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
71 lines (58 loc) · 1.76 KB
/
Copy pathapp.js
File metadata and controls
71 lines (58 loc) · 1.76 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
import * as moviesData from "./data/movies.js"
import {dbConnection, closeConnection} from './config/mongoConnection.js';
import {movies} from './config/mongoCollections.js'
import express from 'express';
const app = express();
import session from 'express-session';
import configRoutes from './routes/index.js';
import multer from 'multer';
import exphbs from 'express-handlebars';
const upload = multer();
import cookieParser from 'cookie-parser';
import { requireLogin } from './middleware.js';
//found multer on npm website when I searched up upload stuff middleware https://www.npmjs.com/package/multer
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
//this is for the partials to allow for the nested comment logic
const handlebarsInstance = exphbs.create({
partialsDir: ['views/partials/']
});
app.engine('handlebars', handlebarsInstance.engine);
app.set('view engine', 'handlebars');
app.use(
session({
name: 'Letterboxd_Session',
secret: "Cool Site",
saveUninitialized: false,
resave: false,
cookie: { maxAge: 600000 }
})
);
app.use((req,res,next) => {
if(req.session.user)
{
req.user = req.session.user;
req.userId = req.session.user._id;
req.username = req.session.user.username;
}
next();
});
app.use(express.static('public'));
configRoutes(app);
app.listen(3000, () => {
console.log("We've now got a server!");
});
try {
const movieCollection = await movies()
const count = await movieCollection.countDocuments()
if (count > 0) {
console.log("Database already seeded - skipping seeding.")
} else {
await moviesData.seedDatabase()
console.log("Success!")
}
} catch (e) {
console.log(e)
}
console.log("Your routes will be running on http://localhost:3000")