2023-10-28 23:22:18 -04:00
|
|
|
const express = require('express');
|
|
|
|
const app = express();
|
|
|
|
const port = 3000;
|
|
|
|
|
2023-11-26 00:57:08 -05:00
|
|
|
// grab app and node.js process data
|
|
|
|
const pjson = require('./package.json');
|
|
|
|
const { versions } = require('node:process');
|
|
|
|
|
|
|
|
// register app and node.js versions with views;
|
|
|
|
app.locals.app_version = pjson.version;
|
|
|
|
app.locals.node_version = versions.node;
|
|
|
|
|
|
|
|
// initialize database
|
|
|
|
const sequelize = require('./src/models');
|
|
|
|
sequelize.sync({}).then(function(){
|
|
|
|
console.log('database has been synced');
|
|
|
|
}).catch(function(){
|
|
|
|
console.log('unable to sync database');
|
|
|
|
});
|
|
|
|
|
|
|
|
// enable sessions
|
|
|
|
const session = require("express-session");
|
|
|
|
app.use(session({ resave: true, secret: "123456", saveUninitialized: true }));
|
|
|
|
|
2023-11-26 02:07:20 -05:00
|
|
|
// enable body-parser to read form data
|
|
|
|
const bodyParser = require('body-parser');
|
|
|
|
app.use(bodyParser.urlencoded({ extended: true }));
|
|
|
|
|
2023-10-28 23:22:18 -04:00
|
|
|
// enable the Twig template engine
|
|
|
|
app.set('view engine', 'twig');
|
|
|
|
|
|
|
|
// enable serving static files
|
|
|
|
app.use(express.static('public'));
|
|
|
|
|
|
|
|
// load routes
|
|
|
|
const indexRoutes = require('./src/routes/index');
|
2023-11-26 02:07:20 -05:00
|
|
|
const projectRoutes = require('./src/routes/project');
|
2023-11-26 12:54:09 -05:00
|
|
|
const hardwareRoutes = require('./src/routes/hardware');
|
2023-11-27 00:42:42 -05:00
|
|
|
const benchmarkRoutes = require('./src/routes/benchmark');
|
2023-10-28 23:22:18 -04:00
|
|
|
|
|
|
|
// register routes
|
|
|
|
app.get('/', indexRoutes.getIndex);
|
2023-11-26 12:54:09 -05:00
|
|
|
// project routes
|
2023-11-26 02:07:20 -05:00
|
|
|
app.get('/project', projectRoutes.getIndex);
|
|
|
|
app.get('/project/list', projectRoutes.getList);
|
|
|
|
app.get('/project/add', projectRoutes.getAdd);
|
|
|
|
app.post('/project/add', projectRoutes.postAdd);
|
2023-11-26 12:54:09 -05:00
|
|
|
app.get('/project/:project_id', projectRoutes.getView);
|
|
|
|
// hardware routes
|
|
|
|
app.get('/hardware', hardwareRoutes.getIndex);
|
|
|
|
app.get('/hardware/list', hardwareRoutes.getList);
|
|
|
|
app.get('/hardware/add', hardwareRoutes.getAdd);
|
|
|
|
app.post('/hardware/add', hardwareRoutes.postAdd);
|
|
|
|
app.get('/hardware/:hardware_id', hardwareRoutes.getView);
|
2023-11-27 00:42:42 -05:00
|
|
|
// benchmark routes
|
|
|
|
app.get('/benchmark', benchmarkRoutes.getIndex);
|
|
|
|
app.get('/benchmark/list', benchmarkRoutes.getList);
|
|
|
|
app.get('/benchmark/add', benchmarkRoutes.getAdd);
|
|
|
|
app.post('/benchmark/add', benchmarkRoutes.postAdd);
|
|
|
|
app.get('/benchmark/:benchmark_id', benchmarkRoutes.getView);
|
2023-10-28 23:22:18 -04:00
|
|
|
|
|
|
|
app.listen(port, () => {
|
|
|
|
console.log(`Leviathan listening on port ${port}`);
|
|
|
|
});
|