http.createServer(function (req, res) { var url = URL.parse(req.url); res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(fs.readFileSync(__dirname + url.pathname)); })
// Initializes the server and mounts it in the generated build directory. http.createServer((req, res) => { // If we are accessing the root, it should be redirected to the default language, // We shouldn't get a 404 page. if (req.url === '/') { req.url = `/${mainLocale}` } mount(req, res) }).listen(port, () => { console.log(`\x1B[32mServer running at http://localhost:${port}/${mainLocale}/\x1B[39m`) })
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(); } })
this.redirector = http.createServer((req, res) => { res.writeHead(301, { Location: `https://${req.headers.host.split(':')[0]}:${TLS_PORT}${req.url}` }); res.end();
app.prepare().then(() => { createServer((req, res) => { const parsedUrl = parse(req.url, true) handle(req, res, parsedUrl) }).listen(port, err => { if (err) throw err console.log(`> Ready on http://localhost:${port}`) }) })
http.createServer(function(req, res) { const query = url.parse(req.url, true).query; totalSales(query.item).then(function(sum) { res.writeHead(200); res.end(`Total sales for item ${query.item} is ${sum}`); }); }).listen(8000, function() {console.log('Started')});
https.createServer(options, (req, res) => { console.log(req.url); res.writeHead(200); res.end('hello world\n'); }).listen(6789);
http.createServer((req, res) => { // 跨域 res.setHeader('Access-Control-Allow-Origin', '*'); // 必须要设置 res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); let name = req.url.split('=')[1]; req.pipe(fs.createWriteStream(`./${name}`)); res.end('success'); }).listen(8877);
http.createServer(function (request, response) { //response.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'}); response.writeHead(200, {'Content-Type':'image/jpeg'}); if(request.url!=="/favicon.ico"){ //清除第2此访问 console.log('访问'); //response.write('hello,world');//不能向客户端输出任何字节 optfile.readImg('./1.gif',response); //------------------------------------------------ console.log("继续执行"); //response.end('hell,世界');//end在方法中写过 } }).listen(8000);
https.createServer(options, (req, res) => { console.log(req.url); res.writeHead(200); res.end('hello world\n'); }).listen(6789);