Vscode-live-server: Is router support?

Created on 7 Feb 2018  ·  11Comments  ·  Source: ritwickdey/vscode-live-server

Some project use virtual directory, how can I make it work ?

closed

Most helpful comment

I just find that we only need an file option to solve it.

{
  file: "index.html", // When set, serve this file (server root relative) for every 404 (useful for single-page applications)
}

All 11 comments

Maybe it is related width #39 Basic Routing

I send an pull request #73

add config :

"liveServer.settings.mount": [
        ["/ep920", "./"]
 ]

out put at vscode's console:

image

and it works well.

Wait a minute ! I think #52 & #39 is talking about SPA url rewriting (instead of throwing 404, returns main html file, so that SPA can handle the route).

Is not it ?

@ritwickdey I think they are and I also have the same problem. The server launches fine but when refreshing to a child route I get a 404 because the server can not find a file for /child/path. In my case, this route should be handled by React Router. Can you add a config option that allows the user to specify a default file instead of returning a 404? Defaulting to the file the user used to launch Live Server would be a good idea, too.

Yep, having the same problem here, I want my index.html to be loaded on every url that is requested.

Maybe the middleware option of live-server is useful.

var liveServer = require("live-server");

var params = {
    port: 8181, // Set the server port. Defaults to 8080.
    host: "0.0.0.0", // Set the address to bind to. Defaults to 0.0.0.0 or process.env.IP.
    root: "/public", // Set root directory that's being served. Defaults to cwd.
    open: false, // When false, it won't load your browser by default.
    ignore: 'scss,my/templates', // comma-separated string for paths to ignore
    file: "index.html", // When set, serve this file (server root relative) for every 404 (useful for single-page applications)
    wait: 1000, // Waits for all changes, before reloading. Defaults to 0 sec.
    mount: [['/components', './node_modules']], // Mount a directory to a route.
    logLevel: 2, // 0 = errors only, 1 = some, 2 = lots
    middleware: [function(req, res, next) { next(); }] // Takes an array of Connect-compatible middleware that are injected into the server middleware stack
};
liveServer.start(params);

If it has middleware support , we can use res.redirect , but that require a function type , how can I config a function type in vscode's settings ?

I just find that we only need an file option to solve it.

{
  file: "index.html", // When set, serve this file (server root relative) for every 404 (useful for single-page applications)
}

That should do the job yes :)

A pr for file option support #118 .

@cdswyda Thanks for this PR. These feature is now available in new release. I am closing this issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tehsy97 picture tehsy97  ·  6Comments

mpower02 picture mpower02  ·  6Comments

ninlil picture ninlil  ·  6Comments

julesmqz picture julesmqz  ·  7Comments

kmdrGroch picture kmdrGroch  ·  5Comments