Metzploreur/main.js

42 lines
1 KiB
JavaScript
Raw Normal View History

2023-11-01 02:00:47 +00:00
const path = require('path');
const express = require('express');
const session = require('express-session')
const sessionConfig = require('./config/session')
2023-11-09 17:53:46 +00:00
2023-11-01 02:00:47 +00:00
const mongoDBSessionStore = sessionConfig.createSessionStore(session)
const db = require('./data/database');
const demoRoutes = require('./routes/demo');
const authRoutes = require('./routes/auth');
const postsRoutes = require('./routes/posts');
const authMiddleware = require('./middlewares/auth-middleware');
const app = express();
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use(express.urlencoded({ extended: false }));
app.use(express.static('public'));
2023-11-09 17:53:46 +00:00
2023-11-01 02:00:47 +00:00
app.use(session(sessionConfig.createSessionConfig(mongoDBSessionStore)))
app.use(authMiddleware);
2023-11-09 17:53:46 +00:00
2023-11-01 02:00:47 +00:00
app.use(demoRoutes);
app.use(authRoutes);
app.use(postsRoutes);
2023-11-02 19:15:23 +00:00
app.use('/images', express.static(path.join(__dirname, 'images')));
2023-11-01 02:00:47 +00:00
app.use(function(error, req, res, next) {
res.render('500');
})
db.connectToDatabase().then(function () {
app.listen(3000);
});