Start coding
This commit is contained in:
parent
4b730cb187
commit
0b684bed03
|
@ -1,2 +1,3 @@
|
|||
/node_modules/
|
||||
/nbproject/
|
||||
/rethink.sh
|
62
app.js
62
app.js
|
@ -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)
|
||||
});
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"appPort": "8888",
|
||||
"rtdbHost": "172.17.0.2",
|
||||
"rtdbPort": "28015"
|
||||
}
|
Reference in New Issue