the-social-notebook-server/server/server.js

46 lines
1 KiB
JavaScript

'use strict';
var server;
var express = require('express');
var bodyParser = require('body-parser');
var api = require('./api');
class Server {
constructor() {
console.log('Creating Server');
this.app = express();
// parse application/x-www-form-urlencoded
this.app.use(bodyParser.urlencoded({
extended: false
}));
// parse application/json
this.app.use(bodyParser.json());
this.app.use('/api', api);
this.app.get('/', (req, res) => {
res.status(200)
.send('<h1>The Social Notework<h1><h4>Under Development</h4>');
});
this.app.use((req, res, next) => {
res.statusCode = 404;
res.send('<h1>404 - Daaaa</h1>Not Here - Yo!');
next();
});
}
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;
};