koajs / koa

Expressive middleware for node.js using ES2017 async functions
https://koajs.com
MIT License
35.14k stars 3.23k forks source link

Content Type not working #937

Closed tomatau closed 7 years ago

tomatau commented 7 years ago

I'm building a fairly unusual use-case of a koa app boilerplate and when I try to migrate to koa2, every response is Content-Type: application/octet-stream unless I manually overwrite. This includes responses serving static assets! Most responses are ctx.response.body = "<html>some string</html>" and a few are plain JSON.

NB: My app boilerplate is for a "universal/isomorphic" React boilerplate that abuses babel-runtime compilation and the node require.cache to get live updates to the server code. There's also some funky business with injecting routes and assets at runtime to improve testability. None of these factors affected the auto Content-Type in Koa1 so I've no idea why it would stop working for Koa2?

magicdawn commented 7 years ago

maybe use a koa@2 version koa-static

tomatau commented 7 years ago

maybe I am!

"koa-static": "^3.0.0",

:)

PackageJSON diff:

-    "koa": "^1.2.4",
-    "koa-body": "^1.6.0",
-    "koa-compress": "^1.0.9",
-    "koa-favicon": "^1.2.1",
-    "koa-logger": "~1.3.0",
-    "koa-mount": "~1.3.0",
-    "koa-router": "^5.4.0",
+    "koa": "^2.0.1",
+    "koa-body": "^2.0.0",
+    "koa-compose": "3",
+    "koa-compress": "^2.0.0",
+    "koa-convert": "^1.2.0",
+    "koa-favicon": "^2.0.0",
+    "koa-logger": "^2.0.1",
+    "koa-mount": "^2.0.0",
+    "koa-router": "7",
     "koa-session-store": "^2.0.0",
-    "koa-static": "^2.0.0",
-    "koa-webpack-dev-middleware": "^1.4.4",
+    "koa-static": "^3.0.0",
+    "koa-webpack-middleware": "^1.0.3",

I'm wrapping koa-session-store in a koa-convert as there isn't a koa2 version

PlasmaPower commented 7 years ago

Can you post a minimal example? Most likely, the problem doesn't originate from Koa itself.

tomatau commented 7 years ago

I've drilled down to it being a problem with the "koa-webpack-middleware".

https://github.com/leecade/koa-webpack-middleware/blob/master/middleware/hotMiddleware.js#L7-L8

Thanks