overseer/index.js

69 lines
2.0 KiB
JavaScript
Raw Normal View History

2022-11-01 23:55:07 -04:00
const express = require('express');
const session = require('express-session');
const RedisStore = require('connect-redis')(session);
2022-11-04 17:54:43 -04:00
// const flash = require('express-flasher');
2022-11-01 23:55:07 -04:00
// instantiate new express.js app
const app = express();
const config = require('config');
2022-11-01 23:55:07 -04:00
2022-11-02 13:45:40 -04:00
// initialize database connection
(async () => {
const db = require('./src/models');
2022-11-03 22:28:01 -04:00
await db.sequelize.sync({
alter: true,
});
})();
2022-11-02 13:45:40 -04:00
// initialize Redis store for session data
const redisClient = require('./src/redis');
// initialize express.js session w/ Redis datastore
app.use(session({
store: new RedisStore({
client: redisClient,
}), // use Redis datastore
resave: false, // don't save session if unmodified
saveUninitialized: false, // don't create session until something stored
secret: 'lord of the rings',
}));
// setup flash messaging
2022-11-04 17:54:43 -04:00
// app.use(flash.flash());
// app.use(flash.flashRead());
2022-11-02 13:45:40 -04:00
// set up body POST parameters
app.use(express.json());
2022-11-03 22:28:01 -04:00
app.use(express.urlencoded({
extended: true,
}));
2022-11-02 13:45:40 -04:00
2022-11-01 23:55:07 -04:00
// load the template engine
app.set('view engine', 'twig');
// enable static file serving
app.use(express.static('public'));
// load route handlers
const homeRoutes = require('./src/routes/home');
2022-11-02 13:45:40 -04:00
const itemRoutes = require('./src/routes/item');
const licenseRoutes = require('./src/routes/license');
2022-11-01 23:55:07 -04:00
// register route handlers
app.get('/', homeRoutes.getIndex);
2022-11-02 13:45:40 -04:00
app.get('/item/add', itemRoutes.getAdd);
app.post('/item/add', itemRoutes.postAdd);
app.get('/item/:id', itemRoutes.getItem);
2022-11-03 22:08:45 -04:00
app.get('/item/:id/edit', itemRoutes.getItemEdit);
app.post('/item/:id/edit', itemRoutes.postItemEdit);
app.get('/license/add', licenseRoutes.getAdd);
app.post('/license/add', licenseRoutes.postAdd);
2022-11-06 11:40:45 -05:00
app.get('/license/:id', licenseRoutes.getLicense);
app.get('/license/:id/edit', licenseRoutes.getEdit);
app.post('/license/:id/edit', licenseRoutes.postEdit);
2022-11-01 23:55:07 -04:00
// start app
app.listen(config.get('server.port'), config.get('server.address'), () => {
console.log(`Overseer is listening on port ${config.get('server.port')}.`);
2022-11-01 23:55:07 -04:00
});