Reorganized routes code into a separate file
This commit is contained in:
parent
34faecc52c
commit
286219c5ea
28
index.js
28
index.js
@ -32,32 +32,8 @@ app.set('view engine', 'twig');
|
||||
// enable serving static files
|
||||
app.use(express.static('public'));
|
||||
|
||||
// load routes
|
||||
const indexRoutes = require('./src/routes/index');
|
||||
const projectRoutes = require('./src/routes/project');
|
||||
const hardwareRoutes = require('./src/routes/hardware');
|
||||
const benchmarkRoutes = require('./src/routes/benchmark');
|
||||
|
||||
// register routes
|
||||
app.get('/', indexRoutes.getIndex);
|
||||
// project routes
|
||||
app.get('/project', projectRoutes.getIndex);
|
||||
app.get('/project/list', projectRoutes.getList);
|
||||
app.get('/project/add', projectRoutes.getAdd);
|
||||
app.post('/project/add', projectRoutes.postAdd);
|
||||
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);
|
||||
// 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);
|
||||
// load routes to express
|
||||
require('./src/routes')(app);
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Leviathan listening on port ${port}`);
|
||||
|
@ -1,9 +1,33 @@
|
||||
const Project = require('../models').models.Project;
|
||||
// load routes
|
||||
const topRoutes = require('./toplevel');
|
||||
const projectRoutes = require('./project');
|
||||
const hardwareRoutes = require('./hardware');
|
||||
const benchmarkRoutes = require('./benchmark');
|
||||
|
||||
module.exports = function(app) {
|
||||
|
||||
// top-level routes
|
||||
app.get('/', topRoutes.getIndex);
|
||||
|
||||
// project routes
|
||||
app.get('/project', projectRoutes.getIndex);
|
||||
app.get('/project/list', projectRoutes.getList);
|
||||
app.get('/project/add', projectRoutes.getAdd);
|
||||
app.post('/project/add', projectRoutes.postAdd);
|
||||
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);
|
||||
|
||||
// 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);
|
||||
|
||||
// GET / - primary app dashboard
|
||||
exports.getIndex = async function(req, res) {
|
||||
var projects = await Project.findAll();
|
||||
res.render('index/dashboard', {
|
||||
projects: projects
|
||||
});
|
||||
};
|
||||
|
9
src/routes/toplevel.js
Normal file
9
src/routes/toplevel.js
Normal file
@ -0,0 +1,9 @@
|
||||
const Project = require('../models').models.Project;
|
||||
|
||||
// GET / - primary app dashboard
|
||||
exports.getIndex = async function(req, res) {
|
||||
var projects = await Project.findAll();
|
||||
res.render('index/dashboard', {
|
||||
projects: projects
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue
Block a user