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

Running "json-server --watch ./data/db.json --port 8000 --routes ./data/routes.json" results in the error "Unknown option '--routes'"

Open SteveGFortescue opened this issue 1 year ago • 16 comments

I can't see this issue documented anywhere else and have tried different versions of json-server

Running on Apple M1 Pro Node: 20.9.0 json-server: 1.0.0-alpha.23

Have tried running from npx, json-server as global as well as local and both. running the following json-server --watch ./data/db.json --port 8000 --routes ./data/routes.json results in the error below

`npx json-server --watch ./data/db.json --port 8000 --routes ./data/routes.json

Unknown option '--routes' Usage: json-server [options]

Options: -p, --port Port (default: 3000) -h, --host Host (default: localhost) -s, --static

Static files directory (multiple allowed) --help Show this message --version Show version number`

The documentation says --routes is an option but the package in npm does not contain it?

image

SteveGFortescue avatar Feb 06 '24 05:02 SteveGFortescue

afaik this option is not available in 1.0.0 The documentation for --routes only refers to 0.x.x releases

homj avatar Feb 07 '24 14:02 homj

Will this option be available in the final v1 version?

hamidmayeli avatar Feb 15 '24 11:02 hamidmayeli

How else can we make API routes that are level 2 or deeper? For example /api/users ?

leeyh20 avatar Feb 25 '24 14:02 leeyh20

I went back to older version

SaimonL avatar Feb 27 '24 17:02 SaimonL

It doesn't make sense to remove a feature after it's been out?

Alejandroem avatar Apr 17 '24 03:04 Alejandroem

This change is unfortunate. I attempted to use json-server for the Angular Tour of Heroes tutorial, but the URL in that example is "api/heroes" and so I really needed the --routes support to strip out the "api" prefix.

I suppose as a work-around I can fiddle with the environment config in Angular to parameterized the URL, but it's simpler to just have the prefix stripped out when using json-server instead of HttpClientInMemoryWebApiModule.

matthewjheaney avatar May 28 '24 04:05 matthewjheaney

I went back to older version

What version?

douglasio avatar Jun 01 '24 20:06 douglasio

I downgraded to the latest stable version (0.17.4) and I still see the error message “Unknown option ‘--routes’”.

VasylenkoIhor avatar Jun 03 '24 15:06 VasylenkoIhor

Just use the "json-server": "^0.17.4" in your package.json. Unfortunately, the documentation does not match the latest version of json-server, which is "1.0.0-beta.1", as I am writing this comment. Routes are not included in the latest release.

webmasterdevlin avatar Jun 30 '24 19:06 webmasterdevlin

Is this feature intentionally missing from the beta version? Just wanting to know if this is a feature that will be available in later stable releases.

dillonrowan avatar Jul 05 '24 14:07 dillonrowan

@dillonrowan 0.x.x was built on express, v1.x.x uses tinyhttp with no documented rewrite option. Tried to modify url using Th middleware with no luck.

aweigor avatar Jul 19 '24 15:07 aweigor

I downgraded to the latest stable version (0.17.4) and I still see the error message “Unknown option ‘--routes’”.

That is false information!

v0.17.4 works!

npm remove json-server
npm install [email protected]
npx json-server --watch db.json --routes routes.json --port 8089
  \{^_^}/ hi!

  Loading db.json
  Loading routes.json
  Done
...

bor8 avatar Aug 23 '24 08:08 bor8

@typicode please bump @tinyhttp/app to v2.4, it should be fixed now

v1rtl avatar Sep 11 '24 14:09 v1rtl

It was really confusing how this option is missing with no warning, I dont have any apis that are only 1 level deep. This library is pretty much useless without routes.json support

tim-soft avatar Sep 17 '24 16:09 tim-soft

npm remove json-server npm install [email protected] npx json-server --watch db.json --routes routes.json --port 8089

realmente essa solução funciona:

image

lucenasoft avatar Dec 13 '24 19:12 lucenasoft

What a casual way to share this information.

winnemucca avatar Feb 19 '25 04:02 winnemucca