2018-07-30 16:59:41 -04:00
|
|
|
const PORT = 8090;
|
2018-07-23 16:58:23 -04:00
|
|
|
var express = require('express');
|
2022-07-03 00:11:53 -04:00
|
|
|
const formidable = require('express-formidable');
|
2018-07-23 16:58:23 -04:00
|
|
|
var app = express();
|
|
|
|
|
2022-07-03 00:11:53 -04:00
|
|
|
app.use(formidable());
|
|
|
|
|
2021-06-07 20:35:05 -04:00
|
|
|
console.log('Starting express server on port ' + PORT);
|
2018-07-25 08:23:17 -04:00
|
|
|
|
2018-07-23 16:58:23 -04:00
|
|
|
// set the view engine to ejs
|
|
|
|
app.set('view engine', 'ejs');
|
|
|
|
|
2018-07-25 08:23:17 -04:00
|
|
|
// add folder for static content:
|
|
|
|
app.use(express.static(__dirname + '/assets'));
|
2018-07-23 16:58:23 -04:00
|
|
|
|
2022-06-20 21:55:50 -04:00
|
|
|
app.get(/\/.*/, function (req, res) {
|
2018-07-27 13:32:34 -04:00
|
|
|
let pathname = 'pages' + req.path;
|
2018-07-31 16:09:51 -04:00
|
|
|
let page = pathname.substr(pathname.lastIndexOf('/') + 1);
|
2021-06-07 20:35:05 -04:00
|
|
|
|
2018-07-31 16:09:51 -04:00
|
|
|
if (pathname !== null && pathname !== undefined) {
|
|
|
|
if ((pathname)[pathname.length - 1] === '/') {
|
|
|
|
pathname += 'index';
|
|
|
|
page = 'index';
|
|
|
|
}
|
|
|
|
if (pathname.includes('projects') && page !== 'index') {
|
|
|
|
// projects has a custom template that is used for all projects
|
|
|
|
// so we need to change the pathname that the renderer is using
|
2019-11-22 00:43:29 -05:00
|
|
|
// that template:
|
2018-07-31 16:09:51 -04:00
|
|
|
pathname = pathname.substr(0, pathname.lastIndexOf(page));
|
|
|
|
pathname += 'project_template'
|
2019-11-22 00:43:29 -05:00
|
|
|
// provide the pagename for project_template to use for main content
|
2022-06-20 21:55:50 -04:00
|
|
|
page = 'partials/md/projects/' + page;
|
|
|
|
}
|
|
|
|
else if (pathname.includes('recipes') && page !== 'index') {
|
|
|
|
pathname = pathname.substr(0, pathname.lastIndexOf(page));
|
|
|
|
pathname += 'recipe_template'
|
|
|
|
// provide the pagename for project_template to use for main content
|
|
|
|
page = 'partials/md/recipes/' + page;
|
2018-07-31 16:09:51 -04:00
|
|
|
}
|
2018-07-27 13:32:34 -04:00
|
|
|
}
|
2018-07-31 16:09:51 -04:00
|
|
|
console.log('request for path: ' + pathname + ', and page: ' + page);
|
2018-07-27 13:32:34 -04:00
|
|
|
|
2022-06-20 21:55:50 -04:00
|
|
|
res.render(pathname, { "page": page });
|
2018-07-27 13:32:34 -04:00
|
|
|
});
|
|
|
|
|
2022-07-03 00:11:53 -04:00
|
|
|
app.post("/new_recipe", function (req, res) {
|
|
|
|
console.log(JSON.stringify(req.fields));
|
|
|
|
res.send('mission success');
|
|
|
|
});
|
|
|
|
|
2019-11-22 00:43:29 -05:00
|
|
|
app.listen(PORT);
|