Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build a list of native or Polka-compatible middleware #85

Open
guilhermeoc97 opened this issue Feb 1, 2019 · 8 comments
Open

Build a list of native or Polka-compatible middleware #85

guilhermeoc97 opened this issue Feb 1, 2019 · 8 comments

Comments

@guilhermeoc97
Copy link

guilhermeoc97 commented Feb 1, 2019

Pretty much what it says on the title. It would be awesome to know which middlewares are compatible with Polka or made exclusively with Polka in mind.

So far I haven't found any, but maybe some middleware can break while running on Polka because it uses IncomingMessage and ServerResponse while Express uses their own implementation of a request module and a response module.

If deemed unnecessary, the issue can be closed. But for now, here are the lists:

Native to Polka

  • sirv

Compatible, tested by the creator

  • body-parser
  • cors
  • compression
  • morgan
  • sapper
  • serve-static

Compatible, tested by users

  • express-fileupload
  • helmet
  • http-proxy-middleware
  • response-time
  • favicon

Incompatible

  • Nothing so far
@neves
Copy link

neves commented Apr 24, 2019

I can share the ones that I'm using:

  1. response-time
  2. cors
  3. morgan
  4. favicon
  5. body-parser

@GrosSacASac
Copy link

@GrosSacASac
Copy link

Recently made onewaydata compatible with polka

@fraxken
Copy link

fraxken commented Dec 2, 2019

multer seem to bug with polka (unhandled promises when the fileSize limit is reached). I use make-promises-safe so my server as been shutted down. I guess there is a problem around how the error is handled in the inner multer middleware.

@lukeed
Copy link
Owner

lukeed commented Dec 3, 2019

@fraxken what version of polka? can you provide a small repo?

@fraxken
Copy link

fraxken commented Dec 4, 2019

@lukeed https://github.com/fraxken/polka_multer

At first i failed to reproduce the problem (so i get back to my project to reproduce on it and found what could produce a difference).

The bug only appear if i create a new polka instance at create the route on it

const app = polka({ onError });

const router = polka();
router.post("/avatar", upload.single("avatar"), async (req, res) => {

});
app.use("/api", router);

Make no sense to do this in the reproduction sure (but in my app i require many "sub-routes" to use them in the /api namespace).

It produce the following error

_http_server.js:237
    throw new ERR_HTTP_INVALID_STATUS_CODE(originalStatusCode);
    ^

RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: LIMIT_FILE_SIZE
    at ServerResponse.writeHead (_http_server.js:237:11)
    at ServerResponse._implicitHeader (_http_server.js:228:8)
    at write_ (_http_outgoing.js:616:9)
    at ServerResponse.end (_http_outgoing.js:733:5)
    at Polka.onError (F:\Code\synergized\node-server\node_modules\polka\index.js:22:6)
    at next (F:\Code\synergized\node-server\node_modules\polka\index.js:94:32)
    at Immediate._onImmediate (F:\Code\synergized\node-server\node_modules\multer\lib\make-middleware.js:53:37)
    at processImmediate (internal/timers.js:441:21) {
  code: 'ERR_HTTP_INVALID_STATUS_CODE'
}

Maybe i missed something on how to use this properly.. not sure.

Best Regards,
Thomas

@ohmdob
Copy link

ohmdob commented Feb 11, 2020

Work for me to avoid Server crashed

	.post('/uploadfile', function (req, res, next) {
		const uploadCb = upload.single('file')
		uploadCb(req, res, function (err) {
			if (err instanceof multer.MulterError) {
				res.writeHead(500);
				res.end('A Multer error occurred when uploading.');
			} else if (err) {
				res.writeHead(500);
				res.end('An unknown error occurred when uploading.');
			}
			res.writeHead(200, { 'Content-Type': 'application/json' });
			res.end(JSON.stringify(req.file));
		})
	})

More information
https://github.com/expressjs/multer
[Error Handing]

@floratmin
Copy link

I build a lightweight and extendable body-parser like middleware:
modular-body

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants