73 lines
1.8 KiB
JavaScript
73 lines
1.8 KiB
JavaScript
const express = require('express'),
|
|
async = require('async'),
|
|
cors = require("cors"),
|
|
app = express(),
|
|
log = require("color-logs")(true, true, "Dryusdan.fr"),
|
|
fs = require("fs"),
|
|
path = require('path'),
|
|
hbs = require('hbs');
|
|
|
|
log.info("Application started and now preparing");
|
|
|
|
var corsOptions = {
|
|
"origin": "*",
|
|
"Access-Control-Allow-Origin": "*",
|
|
"methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
|
|
"preflightContinue": false
|
|
};
|
|
|
|
hbs.registerHelper('list', function(tabs, options) {
|
|
|
|
var out = '';
|
|
for(var x in tabs){
|
|
for(var i in tabs[x]){
|
|
out = out + "" + options.fn(tabs[x][i]) + "";
|
|
}
|
|
}
|
|
return out;
|
|
});
|
|
|
|
|
|
const config = require("./config.json");
|
|
var Template = require("./classes/Template.class");
|
|
|
|
class App {
|
|
constructor(rootPath, port){
|
|
|
|
app.listen(port);
|
|
log.info("HTTP server listening on port", port);
|
|
log.info("Application ready");
|
|
var template = new Template();
|
|
|
|
app.get("/", function(req, res){
|
|
template.render(function(tplData){
|
|
res.setHeader("Content-type", "text/html");
|
|
res.render('template.hbs', tplData);
|
|
});
|
|
});
|
|
app.get("/:slug", function(req, res){
|
|
res.setHeader("Content-type", "text/plain");
|
|
|
|
res.end("Slug : "+req.params.slug);
|
|
});
|
|
app.get("/article/:slug", function(req, res){
|
|
res.setHeader("Content-type", "text/plain");
|
|
|
|
res.end("Slug : "+req.params.slug);
|
|
});
|
|
app.use(express.static("./public"));
|
|
}
|
|
|
|
}
|
|
|
|
new App("/", config.appPort);
|
|
|
|
/** Preparing cache **/
|
|
/*async.waterfall([
|
|
function generateCache(callback){
|
|
callback;
|
|
}
|
|
], function (err){
|
|
|
|
}
|
|
);*/ |