From ed79cc3382d85278aa85185b8355e88974c1d6f3 Mon Sep 17 00:00:00 2001 From: RozaShafik <45145174+RozaShafik@users.noreply.github.com> Date: Wed, 11 Sep 2019 17:18:51 +0200 Subject: [PATCH 1/2] Create index.js --- Week1/index.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Week1/index.js diff --git a/Week1/index.js b/Week1/index.js new file mode 100644 index 000000000..688d50b4c --- /dev/null +++ b/Week1/index.js @@ -0,0 +1,39 @@ +'use strict'; +const http = require('http'); +/* `createServer` MUST return an instance of `http.Server` otherwise the tests + * will fail. + */ +function createServer(port) { + let state = 10; + const server = http.createServer((request, response) => { + // TODO: Write your homework code here + switch (request.url) { + case '/state': + response.writeHead(200, { 'Content-Type': 'application/json' }); + response.end(JSON.stringify({ state: state })); + break; + case '/add': + state++; + response.writeHead(200, { 'Content-Type': 'application/json' }); + response.end(JSON.stringify({ state: state })); + break; + case '/subtract': + state--; + response.writeHead(200, { 'Content-Type': 'application/json' }); + response.end(JSON.stringify({ state: state })); + break; + case '/reset': + state = 10; + response.writeHead(200, { 'Content-Type': 'application/json' }); + response.end(JSON.stringify({ state: state })); + break; + default: + response.writeHead(404, { 'Content-Type': 'application/json' }); + response.end(JSON.stringify({ error: 'Not found' })); + } + }); + return server; +} +module.exports = { + createServer +}; From b7a2a50370d05237171ed305c52948d546a4ddca Mon Sep 17 00:00:00 2001 From: RozaShafik <45145174+RozaShafik@users.noreply.github.com> Date: Wed, 11 Sep 2019 17:19:25 +0200 Subject: [PATCH 2/2] Delete index.js --- Week1/index.js | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 Week1/index.js diff --git a/Week1/index.js b/Week1/index.js deleted file mode 100644 index 688d50b4c..000000000 --- a/Week1/index.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; -const http = require('http'); -/* `createServer` MUST return an instance of `http.Server` otherwise the tests - * will fail. - */ -function createServer(port) { - let state = 10; - const server = http.createServer((request, response) => { - // TODO: Write your homework code here - switch (request.url) { - case '/state': - response.writeHead(200, { 'Content-Type': 'application/json' }); - response.end(JSON.stringify({ state: state })); - break; - case '/add': - state++; - response.writeHead(200, { 'Content-Type': 'application/json' }); - response.end(JSON.stringify({ state: state })); - break; - case '/subtract': - state--; - response.writeHead(200, { 'Content-Type': 'application/json' }); - response.end(JSON.stringify({ state: state })); - break; - case '/reset': - state = 10; - response.writeHead(200, { 'Content-Type': 'application/json' }); - response.end(JSON.stringify({ state: state })); - break; - default: - response.writeHead(404, { 'Content-Type': 'application/json' }); - response.end(JSON.stringify({ error: 'Not found' })); - } - }); - return server; -} -module.exports = { - createServer -};