-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainServer.js
33 lines (30 loc) · 1.02 KB
/
mainServer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"use strict";
//Declaring imports.
const http = require('http');
const httpdispatcher = require('httpdispatcher');
const generatedPages = require('./source/generatedPages');
// Main function
if (require.main === module) {
//Create a server
let dispatcher = new httpdispatcher();
// Inline function to use the local dispatcher.
let server = http.createServer(function(request, response) {
try {
//log the request on console
console.log(request.url);
//Disptach
dispatcher.dispatch(request, response);
}
catch (err) {
console.log(err);
}
});
// Setting the routing for the dispatcher.
generatedPages.configureDispatcher(dispatcher);
//Lets start our server
// Listening to the environment $PORT
server.listen(process.env.PORT, function() {
//Callback triggered when server is successfully listening. Hurray!
console.log("Server listening on: http://localhost:%s", process.env.PORT);
});
}