diff --git a/b3-dev/live/session1/server.js b/b3-dev/live/session1/server.js new file mode 100644 index 0000000..81526c5 --- /dev/null +++ b/b3-dev/live/session1/server.js @@ -0,0 +1,37 @@ +const http = require('http') +const url = require('url'); + +function json_response(code, object, response) { + response.statusCode = 200; + response.setHeader('content-type', 'Application/json'); + response.end(JSON.stringify(object)); +} + + +const server = http.createServer(function (request, response) { + parsedUrl = url.parse(request.url, false); + if(request.method === "POST") { + console.log('POST'); + if(parsedUrl.query.param) + { + json_response(200,parsedUrl.query,response); + } + else + { + json_response(400,{error:"missing required param"},response); + } + } + else if(request.method === "PUT") { + console.log('PUT'); + json_response(200,{status : "where should I put it ?"},response); + } + else if(request.method === "DELETE") { + console.log('DELETE'); + json_response(200,{status : "no delete available"},response); + } + else + { + json_response(200,{status : "active"},response); + } +}); +server.listen(8080);