[英]Getting the Server.serve status code using node-static in Typescript
我正在嘗試在Typescript中編寫一些節點靜態示例代碼,但出現了錯誤
類型“錯誤”不存在屬性“狀態”
這是我的錯誤代碼
import * as server from 'node-static';
import * as http from "http"
var fileServer = new server.Server('./images');
http.createServer(function (request, response) {
request.addListener('end', function () {
var callback: server.Callback;
callback = function (e: Error) {
if (e && (e.status === 404)) { // Error in this line
fileServer.serveFile('/not-found.html', 404, {}, request, response);
}
};
fileServer.serve(request, response, callback)
}).resume();
}).listen(8080);
錯誤的類型為字符串,並且為堆棧跟蹤,因此明確了打字錯誤的原因。
我的問題是如何獲取狀態碼。
原始的JavaScript代碼在這里
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.