Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions week1/homework/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,31 @@ function createServer(port) {

const server = http.createServer((request, response) => {
// TODO: Write your homework code here
if (req.method === 'GET' && req.url === '/state') {
res.writeHead(200, { 'Content-Type' : 'application/json'});
res.end(JSON.stringify({state: state}));
}
else if (req.method === 'GET' && req.url === '/reset') {
state = 10;
res.writeHead(200, { 'Content-Type' : 'application/json'});
res.end(JSON.stringify({ state:state}));
}
else if (req.method === 'GET' && req.url === '/add') {
state++;
res.writeHead(200, { 'Content-Type': 'application/json'});
res.end(JSON.stringify({state: state}));
}
else if (req.method === 'GET' && req.url === '/subtract') {
state--;
res.writeHead(200, { 'Content-Type' : 'application/json'});
res.end(JSON.stringify({state: state}));
}
else {
res.writeHead(404, {'Content-Type': 'application/json'});
res.end(JSON.stringify({error: 'Not found'}));
}
});


return server;
}
Expand Down