-1
我編寫了一個非常簡單的程序來演示Node中的請求處理(實際上是遵循教程),但服務器似乎需要永遠迴應GET /
請求。這裏是我使用的代碼:節點花費太多時間來響應
const http = require('http');
const url = require('url');
let routes = {
'GET': {
'/': (req, res) => {
res.writeHead(200, {'Content-type': 'text/html'});
res.end('GET /');
}
},
'POST': {
},
'NA': (req, res) => {
res.writeHead(404);
res.end('Content not found');
}
}
function router(req, res) {
let baseURI = url.parse(req.url, true);
// the function that gets resolved and used to handle the request
let resolveRoute = routes[req.method][baseURI.pathname];
}
http
.createServer(router).listen(3001,() => {
console.log('Listening on port 3001');
});
我做錯了什麼?