lwsjs / local-web-server

A lean, modular web server for rapid full-stack development.
MIT License
1.2k stars 85 forks source link

--directory option/flag does not work with npx installs #136

Closed iliandy closed 4 years ago

iliandy commented 4 years ago

--directory option/flag does not work with npx installs. However, it works with -g global installs.

75lb commented 4 years ago

I can't reproduce this, it works for me on macOS. This command hosts the public directory as expected.

$ npx local-web-server --directory public

What OS are you on? Which versions of node and npm are installed? Could you paste the command that is failing please?

75lb commented 4 years ago

closing until I receive more info.

Sytten commented 3 years ago

On MacOS I confirm it doesnt work. It will always serve it from where the command is ran.

75lb commented 3 years ago

@Sytten could you paste an example of a command that doesn't work please.. also include your lws.config.js file if you have one.

75lb commented 3 years ago

I still can't reproduce the issue.. I'm on a mac too and, from my home directory, both these commands correctly serve my Pictures folder. It works as expected.

$ ws -d ~/Pictures/
$ npx local-web-server -d ~/Pictures/
75lb commented 3 years ago

Are you using nvm?

Sytten commented 3 years ago

I am running it inside of a package.json script in a yarn workspace. Actually all options seems ignored.

75lb commented 3 years ago

ok, sounds like a yarn thing (it works fine when installed using npm).. try deleting your dependency tree and installing everything from scratch..

On Sat, 22 Aug 2020, 14:04 Émile Fugulin, notifications@github.com wrote:

I am running it inside the of a package.json in a yarn workspace. Actually all options seems ignored.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/lwsjs/local-web-server/issues/136#issuecomment-678638679, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJQV3AEP53UOCNMJT5UCO3SB666BANCNFSM4JG7UDRA .

Sytten commented 3 years ago

I could not get it to work either with npx. Maybe the flag parsing is messed up when using the scripts in package.json? Is there any way to display it at launch?

75lb commented 3 years ago

running ws --config will print the flags and config parsed at runtime

On Sat, 22 Aug 2020, 14:58 Émile Fugulin, notifications@github.com wrote:

I could not get it to work either with npx. Maybe the flag parsing is messed up when using the scripts in package.json? Is there any way to display it at launch?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/lwsjs/local-web-server/issues/136#issuecomment-678644484, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJQV3ALF2WKDBOVDXWHCPLSB7FIFANCNFSM4JG7UDRA .

Sytten commented 3 years ago

The config seems fine:

{
  port: 8000,
  moduleDir: [
    '.',
    '/Users/Sytten/Projects/MyProject/node_modules/local-web-server'
  ],
  modulePrefix: 'lws-',
  stack: MiddlewareStack [
    BasicAuth,      BodyParser,
    RequestMonitor, Log,
    Cors,           Json,
    Compress,       Rewrite,
    Blacklist,      ConditionalGet,
    Mime,           Range,
    SPA,            Static,
    Index
  ],
  directory: './build',
  spa: 'index.html',
  rewrite: [ '/app/(.*) -> /build/$1' ],
  view: CliView {}
}

So the problem is somewhere else, I will try to create a simple repo to show you the problem. EDIT: Never mind, I found out that I had another webserver on the same port (Python simple http server) but for some reason it did not warn me when starting lws that the port was already used...

75lb commented 3 years ago

I installed yarn to test this myself, taking care to avoid using npm.. i created a test project with this structure:

$ tree
.
├── package.json
├── public
   └── index.html

I ran this install command:

$ yarn add local-web-server

This command worked as expected (hosting the public directory):

$ ./node_modules/.bin/ws --directory public/

I added a start command to package.json:

{
  "name": "yarn-test",
  "author": "Lloyd Brookes <75pound@gmail.com>",
  "version": "0.0.0",
  "description": "yarn-test",
  "scripts": {
    "start": "ws --directory public"
  },
  "dependencies": {
    "local-web-server": "^4.2.1"
  }
}

This command also worked as expected (hosting the public dir):

$ yarn start

I can't reproduce this issue. I will re-open the issue once I see it failing.