http.createServer(function (req, res) { var url = URL.parse(req.url, true), uri = decodeURIComponent(url.pathname), postData = ''; if (paths[uri] !== undefined) { if (req.method === 'POST') { req.on('data', function (chunk) { postData += chunk.toString(); }); req.on('end', function () { if (!req.headers['content-type'] || req.headers['content-type'].indexOf('multipart') !== 0) postData = qs.parse(postData); paths[uri](url, req, res, postData); }); } else { paths[uri](url, req, res); } } else { res.writeHead(404); res.end(); } })
app.use( morgan('combined', { 'stream': logger.stream, // OPTIONS 类型请求不记录在日志中 'skip': (req, res) => req.method === 'OPTIONS' }) );
http.createServer((req, res) => { var path = url.parse(req.url).pathname; if(path != '/') { err(res); return; } log(`${req.method} ${req.url} HTTP/${req.httpVersion}`); log(req.headers); log(''); add(req, res); }).listen(8080);
morgan.token("quality", function getQuality(req) { if (req.pathx === "/resolve" && req.method === "POST") { if (req.body.quality) return req.body.quality; else return "medium*"; } else { return "NA"; } });
http.createServer(function (req, res) { if (req.method === 'POST') { req .pipe(through(write, end)) .pipe(res) } else res.end('thingy.txt') })
http.createServer( (request, response) => { console.log(request.method + ' ' + request.url); new Handler({ request, response }).handle(); } ).on('error', console.error)
http.createServer((req, res) => { if (req.url === '/404') { res.statusCode = 404; res.end('Pas trouvé !') } else { res.end(`Kikou ! Tu as fait un ${req.method} sur ${req.url} !`); } })
http.createServer(function (req, res) { logger.info(`Incoming request: ${req.method} ${req.url}`) logger.debug(req) try { filterRequest(req, argv) return proxy.web(req, res, { target: argv.target }) } catch (err) { logger.error(err, 'Request rejected') res.writeHead(400, { 'Content-Type': 'application/json' }) return res.end(JSON.stringify({ error: 'Request rejected' })) } })
//loads the serverport variable from the configuration file http.createServer(function (req, res) { switch (req.method) { case "GET": displayForm(res); //The Node server will create a webpage using the server function break; case "POST": paymentService.acceptPost(req, res); //The Node server will receive a message using the receiver module break; } }).listen(serverport);
http.createServer(function (req, res) { switch (req.method) { case 'GET': show(req, res); break; case 'POST': upload(req, res); } })
http.createServer((req, res) => { log(`\n\n${req.method} ${req.url} HTTP/${req.httpVersion}`); log(req.headers); log(); if(typeof req.headers['cookie'] === 'undefined') { res.setHeader('Set-cookie', ['name=wangding; Httponly', 'age=42; max-age=1000']); } else { log(req.headers['cookie']); } res.end('hello cookie!'); }).listen(8080);
http.createServer(function (request, response) { // 回调函数接收request和response对象 // 获得HTTP请求的method和url console.log(request.method + ': ' + request.url); // 设置response response.writeHead(200, { 'Content-Type': 'text/html' }); response.end('<h1>Hello world!</h1>'); })
http.createServer(function (req, res) { if (req.method === 'POST') { req.pipe(split()) .pipe(through(write, end)) } res.end() })