-
I'm having this error even with app.get("*", (res, req) => {
try {
const url = req.getUrl();
console.log("SERVING URL", url);
res.onAborted(() => {
console.log(`Aborted request "${url}"`);
});
sendFile(res, url).catch(() => internalServerError(res));
} catch (er) {
internalServerError(res);
}
});
internalServerError(res: HttpResponse) {
res.cork(() => {
res.writeStatus("500 Internal Server Error")
.writeHeader("cache-control", "no-cache")
.end("Internal Server Error");
});
}
serveFile(res: HttpResponse, fileName: string, buf: Buffer) {
res.cork(() => {
if (fileName === "service-worker.js") {
res.writeHeader("service-worker-allowed", "/");
}
res.writeHeader("cache-control", "no-cache")
.writeHeader("content-type", mimeTypes.contentType(fileName) || "text/plain")
.end(buf);
});
}
async sendFile(res: HttpResponse, filePath: string) {
try {
const buf = await fs.readFile(filePath);
serveFile(res, path.basename(filePath), buf);
} catch (er: any) {
console.log(er);
if (er.code !== "ENOENT") {
throw er;
}
notFound(res);
}
}
notFound(res: HttpResponse) {
res.cork(() => {
res.writeStatus("404 Not Found")
.writeHeader("cache-control", "no-cache")
.end("URL Not Found");
});
}
// Logs
SERVING URL /app/index.html
SERVING URL /app/index.html
SERVING URL /app/index.html
SERVING URL /app/index.html
Aborted request "/app/index.html"
Error: Invalid access of discarded (invalid, deleted) uWS.HttpResponse/SSLHttpResponse. This error happens every time I try to continuously refresh a page. It's quite obvious that it's a result of browser terminating premature requests when refreshing pages. Did I miss something from the docs? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
This exact question (in verbatim) was already answered from where you copied it. Read the answer, you clearly aren't handling onAborted. Do you really think, that putting a console.log inside onAborted is "handling it"? As if the library only teased you with mundane tasks that really aren't needed? To handle onAborted is to actually............. Handle, it. It means (like the docs clearly say) the request was aborted and you cannot respond to it. |
Beta Was this translation helpful? Give feedback.
This exact question (in verbatim) was already answered from where you copied it. Read the answer, you clearly aren't handling onAborted. Do you really think, that putting a console.log inside onAborted is "handling it"? As if the library only teased you with mundane tasks that really aren't needed? To handle onAborted is to actually............. Handle, it. It means (like the docs clearly say) the request was aborted and you cannot respond to it.