Start coding

This commit is contained in:
Dryusdan 2017-03-22 21:41:23 +01:00
parent 4b730cb187
commit 0b684bed03
3 changed files with 68 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/node_modules/
/nbproject/
/rethink.sh

62
app.js
View File

@ -0,0 +1,62 @@
const app = require('express')(),
async = require('async'),
r = require('rethinkdb'),
cors = require("cors"),
log = require("color-logs")(true, true, "Dryusdan.fr");
log.info("Application started and now preparing");
var corsOptions = {
"origin": "*",
"Access-Control-Allow-Origin": "*",
"methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
"preflightContinue": false
};
const config = require("./config.json");
class App {
constructor(rootPath, port, rtdbConn){
this.rdbConn = rtdbConn;
app.listen(port);
log.info("HTTP server listening on port", port);
log.info("Application ready");
app.get("/", function(req, res){
res.setHeader("Content-type", "text/plain");
res.end("Hello world");
})
.get("/article/:slug", function(req, res){
res.setHeader("Content-type", "text/plain");
res.end("Slug : "+req.params.slug);
})
}
}
async.waterfall([
function connect(callback) {
log.info("Application connecting to database...");
try {
r.connect({
host: config.rtdbHost,
port: config.rtdbPort,
db: "dryusdan"
}, callback);
} catch (e) {
log.error("Connection failed, retrying...");
}
}
], function (err, connection){
if(err){
log.error(err);
process.exit(1);
return;
}
log.info("Application connected to database");
new App("/", config.appPort, connection)
});

5
config.json Normal file
View File

@ -0,0 +1,5 @@
{
"appPort": "8888",
"rtdbHost": "172.17.0.2",
"rtdbPort": "28015"
}