Node.js 灵活的路由
程序员文章站
2022-04-30 16:58:48
...
Node.js route(路由)
定义router.js文件
定义router.js文件
[code]var http = require('http'); var url = require('url'); function start(route) { var onRequest = function (request, response) { var pathname = url.parse(request.url).pathname; console.log("Request for " + pathname); route(pathname); response.writeHead(200, { "Content-Type" : "text/plain"}); response.write("Hello Zhang Shan"); response.end(); } http.createServer(onRequest).listen(8888); console.log('Server has started'); } exports.start = start;
定义index.js文件
[code]var server = require('./server'); var router = require('./router'); server.start(router.route);
以上就是Node.js 灵活的路由的内容,更多相关内容请关注PHP中文网(www.php.cn)!
上一篇: 详解python如何在前端显示后端的信息
下一篇: 拼音库创设 php