Permalink
Browse files

Step 1.2: Add server basis

  • Loading branch information...
DAB0mB committed Dec 12, 2016
1 parent 85dd5d9 commit f83aa77832c0c61910281664723e2e44ab342e20
Showing with 36 additions and 0 deletions.
  1. +36 −0 server.js
@@ -0,0 +1,36 @@
const Hapi = require("hapi");

let port = 8000;

// Initialize a new server
let server = new Hapi.Server();

server.connection({ port: process.env.PORT || port });

// Report each response made
server.ext("onPreResponse", (req, rep) => {
let res = req.response;

console.log("Outcoming response:");
console.log(`in: ${new Date}`);
console.log(`to: ${req.info.remoteAddress}`);
console.log(`method: ${req.method}`);
console.log(`url: ${req.url.path}`);
console.log(`status: ${res.statusCode || res.output.statusCode}`);
console.log();

rep.continue();
});

// Print message once started
server.start((err) => {
if (err) throw err;

console.log();
console.log("---------- -------- ------ ---- --");
console.log("----- ---- --- -- -");
console.log(`Server running at ${port}`);
console.log("----- ---- --- -- -");
console.log("---------- -------- ------ ---- --");
console.log();
});

0 comments on commit f83aa77

Please sign in to comment.