overseer/index.js

43 lines
1008 B
JavaScript
Raw Permalink Normal View History

2022-11-01 23:55:07 -04:00
const express = require('express');
// instantiate new express.js app
const app = express();
const port = 3000;
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
// 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');
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);
2022-11-01 23:55:07 -04:00
// start app
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});