Skip to content

Rewrite only requests for html files #51

@IgorMinar

Description

@IgorMinar

When SystemJS is misconfigured and it tries to fetch modules via URLs that don't map to js files, lite-server redirects the requests to index.html (or /) in order to support the window.history.pushState location strategy.

The problem with this is that System will typically error with a weird error like Uncaught SyntaxError: Unexpected token <. This error is very difficult to understand and fix.

It would be much better if lite-server error with 404s in this case, giving the developer the correct feedback that the file is not present at this url. This should be achieved without breaking the pushState support for location by distinguishing the SystemJS requests from the application requests. SystemJS makes all requests with Accept: application/x-es-module, */* request header and we can use this to identify these requests and treat them differently from others.

This kind of treatment of different requests might be useful for other kinds of errors in general (e.g. image fetches). So it might actually be better to change the server to rewrite only requests with request header Accept:text/html,application/xhtml+xml,... which is typically used by the browser to fetch the initial html (which is the only thing we want to rewrite).

screen shot 2016-03-14 at 5 10 31 pm
screen shot 2016-03-14 at 5 11 57 pm

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions