-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
57 lines (38 loc) · 1.22 KB
/
app.js
File metadata and controls
57 lines (38 loc) · 1.22 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
import express from 'express';
import path from 'path';
import {fileURLToPath} from 'url';
import mainRoutes from './routes/mainRoutes.js';
import bodyParser from 'body-parser';
import session from "express-session";
const app = express();
// Middleware dla parsera formularzy
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(express.json());
// Express session configuration
app.use(session({
secret: 'pociągara',
resave: false,
saveUninitialized: true,
cookie: { secure: false }
}));
// middleware for isLoggedIn for all views
app.use((req, res, next) => {
// console.log('Session:', req.session)
res.locals.isLoggedIn = req.session.user && req.session.user.loggedIn;
next();
});
const PORT = process.env.PORT || 8080;
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// middleware for static files
app.use(express.static(path.join(__dirname, 'public')));
// view settings (EJS)
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use(express.static('public'));
// routes
app.use('/', mainRoutes);
app.listen(PORT, () => {
console.log(`Server started on port ${PORT}`);
});