question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crash with fallback GET route

See original GitHub issue

If you run the following test app:

var express = require('express');
var app = express();

require('express-ws')(app);

app.ws('/test', function(ws, req) {
  console.log('incoming connection');
});

app.get('/*', function(req, res, next){
  res.sendFile(__dirname + '/test.html');
});

app.listen(3000);

When you make a WebSocket request to ws://localhost:3000/invalidroute, the process crashes with the following exception:

http_outgoing.js:135
      this.outputSize += this._header.length;
                                     ^

TypeError: Cannot read property 'length' of null
    at ServerResponse.OutgoingMessage._send (_http_outgoing.js:135:38)
    at ServerResponse.OutgoingMessage.write (_http_outgoing.js:477:16)
    at ReadStream.ondata (_stream_readable.js:536:20)
    at emitOne (events.js:90:13)
    at ReadStream.emit (events.js:182:7)
    at readableAddChunk (_stream_readable.js:153:18)
    at ReadStream.Readable.push (_stream_readable.js:111:10)
    at onread (fs.js:1818:12)
    at FSReqWrap.wrapper [as oncomplete] (fs.js:614:17)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:15

github_iconTop GitHub Comments

2reactions
suhasdeshpandecommented, Apr 19, 2017

Is there any workaround on this?

1reaction
nicolasiensencommented, Jul 7, 2020

I’m working on a project that has a middleware to catch all paths that don’t match any route and return an HTML file.

To overcome the problem described in this issue, we added a check in the middleware to skip its action if the request contains the WebSocket header:

const frontendMiddleware = (req, res) => {
  if (req.header('sec-websocket-version') === undefined) {
    res.sendFile(path.join(FRONTEND_ROOT, 'build', 'index.html'))
  }
}

app.use(frontendMiddleware)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Fallback rewrites with catch all route causes a JSON error
The application "follows" rewrites when fetching the JSON content (or doesn't fetch it at all) and doesn't crash. To Reproduce. Clone the repo: ......
Read more >
react-router dynamic segments crash when accessed
You have two URLs: /settings and /settings/account . In that case, if you have your script inclusion in the fallback file being something...
Read more >
Fixing the 'cannot GET /URL' error on refresh with React ...
There are two main ideas for solving this problem. The first, set up both client and server side routing. The second, redirect all...
Read more >
How to Use Fallback Routes | Full Laravel 9 Course - YouTube
This video will show you how you could easily setup a fallback route to avoid 404 pages – Want to learn the most...
Read more >
Hystrix fallback with Zuul and Spring Boot
To set up the route that will handle this fallback you need to implement the getRoute method. If you want to capture all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found