live-server icon indicating copy to clipboard operation
live-server copied to clipboard

How can I serve from a base URL?

Open efc opened this issue 5 years ago • 3 comments

Issue description

On my deployed site the contents of my local directory "root" will be served from "http://my.site/alias". I would like to run live-server so that everything in my local directory "root" appears at "http://127.0.0.1:8080/alias". There is an earlier issue that claimed the implementation of --mount resolved this use case, but I cannot see how to use --mount to accomplish this. Could someone clarify?

In particular, note that my "root" directory has many subdirectories, for example:

root
|
|-- foo
|    |-- apple
|
|-- bar
|    |-- banana
|    |-- orange
|
-- index

If I cd root and use live-server --mount=/alias:./, then requests for /alias/index work but requests for /alias/foo/apple or /alias/bar/banana fail. Meanwhile, requests for /foo/apple or /foo/banana still work, even though I would want them to fail.

In other words, it appears that mount is only affecting the single route . and not it's subdirectories. I suppose I could add more routes, but this can get out of hand when what I really want is to use the alias for everything.

I am hoping that there is a way to use mount to accomplish this. Can someone illuminate this for me? I can't find any detailed documentation on how to use mount properly for this use case.

Software details

  • Command line used for launching live-server: live-server --mount=/alias:./
  • OS: macOS
  • Browser (if browser related): not browser related
  • Node.js version: 8.9.1
  • live-server version: 1.2.0

efc avatar Nov 30 '18 22:11 efc

Try using the proxy, ie

This will essentially forward requests from /alias back to itself

"liveServer.settings.proxy": {
    "enable": true, //set it true to enable the feature.
    "baseUri": "/alias", //from where you want to proxy.
    "proxyUri": "http://127.0.0.1:8080/" //the actual url.
  }

webunderconstruction avatar May 11 '21 00:05 webunderconstruction

I put my projects in a subdomain of my website and I have one unique base / prefix URL for each of them. Something like this:

  • https://projects.bijanprogrammer.com/one
  • https://projects.bijanprogrammer.com/two
  • https://projects.bijanprogrammer.com/three

So when I want to use a link in my code, I need to prefix it with that base URL such as one or two. It's all OK and working on the server but the problem that is in my local system, when I start live-server it will serve from the root URL or / and my links wont work anymore.

I spent hours to find a solution and this actually worked very well for me. Thanks a lot @webunderconstruction .

package.json

{
  "name": "",
  "description": "",
  "scripts": {
    "dev": "live-server --proxy=/app:http://127.0.0.1:8080"
  },
  "devDependencies": {
    "live-server": "^1.2.1"
  }
}

BijanEisapour avatar Aug 05 '21 08:08 BijanEisapour

I found a simply solved, for example for my proyect that i needed to deploy on my github, on my basepath /route, i build the project then a copied on my pc then, i created a folder called "route" (where a i copied my files of the build project), then a i run live-server outside that folder then a went to the route "http://localhost:8080/route" and it worked.

joselmm avatar Jul 27 '23 16:07 joselmm