1 Star 0 Fork 0

bluebug2016/JavaScriptTutorial

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
server2.js 819 Bytes
一键复制 编辑 原始数据 按行查看 历史
bluebug2016 提交于 2022-03-25 17:08 +08:00 . axios
var http = require('http');
var url = require('url');
var cars = [{ name: 'BMW', price: 5500000, city: 'hangzhou' },
{ name: 'BZ', price: 5500000, city: 'hangzhou' },
{ name: 'BAT', price: 5500000, city: 'hangzhou' },
{ name: 'JL', price: 5500000, city: 'hangzhou' }]
http.createServer(function (request, response) {
var pathobj = url.parse(request.url, true);
switch (pathobj.pathname) {
case '/cars':
response.writeHead(200, { 'Content-Type': 'text/json' });
response.end(JSON.stringify(cars));
break;
default:
response.writeHead(200, { 'Content-Type': 'text/html' });
response.end("<h1>请访问/cars</h1>".toString('utf-8'));
break;
}
}).listen(5001);
console.log('Server running at http://127.0.0.1:5001/cars');
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/bluebug2016/java-script-tutorial.git
git@gitee.com:bluebug2016/java-script-tutorial.git
bluebug2016
java-script-tutorial
JavaScriptTutorial
master

搜索帮助