2016-07-02 11:43:00 +00:00
|
|
|
'use strict';
|
2016-07-01 12:28:10 +00:00
|
|
|
var server;
|
|
|
|
var express = require('express');
|
2016-07-01 23:16:04 +00:00
|
|
|
var bodyParser = require('body-parser');
|
2016-07-01 12:35:32 +00:00
|
|
|
var api = require('./api');
|
2016-07-01 12:28:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Server {
|
|
|
|
constructor() {
|
2016-07-02 11:43:00 +00:00
|
|
|
console.log('Creating Server');
|
2016-07-01 12:28:10 +00:00
|
|
|
this.app = express();
|
2016-07-01 23:16:04 +00:00
|
|
|
// parse application/x-www-form-urlencoded
|
|
|
|
this.app.use(bodyParser.urlencoded({
|
|
|
|
extended: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
// parse application/json
|
|
|
|
this.app.use(bodyParser.json());
|
2016-07-01 12:35:32 +00:00
|
|
|
this.app.use('/api', api);
|
2016-07-01 23:16:04 +00:00
|
|
|
this.app.get('/', (req, res) => {
|
|
|
|
res.status(200)
|
|
|
|
.send('<h1>The Social Notework<h1><h4>Under Development</h4>');
|
|
|
|
});
|
2016-07-01 12:35:32 +00:00
|
|
|
|
|
|
|
this.app.use((req, res, next) => {
|
|
|
|
res.statusCode = 404;
|
|
|
|
res.send('<h1>404 - Daaaa</h1>Not Here - Yo!');
|
|
|
|
next();
|
2016-07-01 12:28:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
run() {
|
|
|
|
var _server = this.app.listen(process.env.PORT || '8080', () => {
|
|
|
|
console.log('App listening on port %s', _server.address()
|
|
|
|
.port);
|
|
|
|
console.log('Press Ctrl+C to quit.');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.getInstance = () => {
|
|
|
|
if (!server) {
|
|
|
|
server = new Server();
|
|
|
|
}
|
|
|
|
return server;
|
|
|
|
};
|