Some (but not all) static files fail to be served - ERR_CONTENT_LENGTH_MISMATCH
See original GitHub issueIssue
Setup:
- Deno Version: 1.17 (updated today)
- v8 Version: Not sure, the one shipped with Deno 1.17?
- Typescript Version: 4.5
- Opine Version: 2.0.0
Details
I am using Opine to serve my Angular application’s static files. Angular’s “dist” folder contains :
- index.html (2.2 KB)
- main.js (182 KB, development version, un-minified)
- polyfill.js (44 KB)
- runtime.js (1 KB)
- styles.css (7.7 KB)
My server code :
import { opine, serveStatic } from "https://deno.land/x/opine@2.0.0/mod.ts";
import { distDir } from "./utils.ts"
console.log(`distDir = `, distDir); // Logs "distDir = D:\dev\Dwiki\front\dist", that's correct
const app = opine();
app.use(serveStatic(distDir));
app.get("/", (req, res) => res.sendFile(distDir + "/index.html"))
await app.listen(8090);
console.log(`App listening on http://localhost:8090`);
Result :
When I localhost:8090, some files get loaded, some don’t :
- index.html (2.2 KB) --> OK 200
- main.js (182 KB) --> (failed)net::ERR_CONTENT_LENGTH_MISMATCH
- polyfill.js (44 KB)--> (failed)net::ERR_CONTENT_LENGTH_MISMATCH
- runtime.js (1 KB) --> OK 200
- styles.css ( 7.7 KB) --> OK 200
No error in the terminal or in the browser’s console. All that’s displayed in my terminal is :
distDir = D:\dev\Dwiki\front\dist App listening on http://localhost:8090
If I serve my Angular app with ng serve
, it displays correctly.
I can see the content of index.html
, runtime.js
and styles.css
in the browser’s network tab.
Not sure why some files are served correctly by Deno/Opine, and some (always these two) get (failed)net::ERR_CONTENT_LENGTH_MISMATCH
EDIT
I noticed the two files that fail to be served are also the two heaviest of the lot. I have updated my question, adding the weight of each file, above. It looks like small files (7 KB, 1 KB, 2 KB) are being served normally, but heavier files (44 KB, 182 KB) get ERR_CONTENT_LENGTH_MISMATCH
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (7 by maintainers)
Top GitHub Comments
@cmorten – Here you go! https://github.com/xyzshantaram/opine-content-length-bug
Sorry I couldn’t work on it last year 😉
For the record, I still haven’t tried @cmorten’s fix, because I’m still trying to code a little server using native Deno code (for learning purposes, I want to understand how Deno works before using libraries), and I have the same issue without Opine.
For that matter, I have just opened a similar issue on Deno’s repo: https://github.com/denoland/deno/issues/13362
So… is it an Opine, or a Deno issue after all? 😃
EDIT
It is a “me” issue! I forgot to encapsulate the inner
await
in an anonymous function, it works now. Sorry folks.