ask God to take a look, the app front end can"t get the video resources on my server. Node"s koa framework.
is OK to play in the video tag, and it can also be played or downloaded in the browser.
const mainRouter = require("./routes");
const Koa = require("koa");
require("colors");
const path = require("path");
const koaBody = require("koa-body");
const settings = require("./settings");
const staticServe = path => {
return require("koa-static")(path, {
setHeaders: function(response, path, stats) {
response.setHeader("Cache-Control", `public, ${process.env.NODE_ENV==="production"?"max-age=604800": "no-cache"}`)
}
});
};
const app = new Koa();
app.on("error", err => {
if(!["read ECONNRESET", "write ECONNABORTED", "write ECANCELED"].includes(err.message)) {
console.log(err);
}
});
const {filePath, resource, fs, type} = ctx;
// if(type !== "application/json" && type !== "text/html" && ctx.method === "GET") { //GET
if(filePath && ctx.method === "GET") {
if(ctx.lastModified && ctx.fresh) {
ctx.status = 304;
return
}
const basename = path.basename(ctx.filePath);
let ext = path.extname(ctx.filePath);
ext = ext.replace(".", "");
const extArr = ["jpg", "png", "jpeg", "bmp", "svg", "gif","mp4"];
const name = resource? resource.oname: basename;
if(extArr.includes(ext)) {
ctx.set("Content-Disposition", `inline; filename=${encodeRFC5987ValueChars(name)}; filename*=utf-8""${encodeRFC5987ValueChars(name)}`);
} else {
ctx.set("Content-Disposition", `attachment; filename=${encodeRFC5987ValueChars(name)}; filename*=utf-8""${encodeRFC5987ValueChars(name)}`)
}
console.log(ctx)
ctx.body = fs.createReadStream(filePath);
ctx.set("content-length", (await fs.stat(filePath)).size);
await next();
below is the error message
Error: write ECONNRESET
code: "ECONNRESET"
errno: "ECONNRESET"
headerSent:true
message: "write ECONNRESET"
stack: "Error: write ECONNRESETn at _ errnoException (util.js:1024:11) n at WriteWrap.afterWrite [as oncomplete] (net.js:867:14)"
syscall: "write"