typicode / json-server

Get a full fake REST API with zero coding in less than 30 seconds (seriously)
Other
72.04k stars 6.95k forks source link

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

Open SteveGFortescue opened 5 months ago

SteveGFortescue commented 5 months ago

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

homj commented 5 months ago

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

hamidmayeli commented 5 months ago

Will this option be available in the final v1 version?

leeyh20 commented 4 months ago

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

SaimonL commented 4 months ago

I went back to older version

Alejandroem commented 3 months ago

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

matthewjheaney commented 1 month ago

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.

douglasio commented 1 month ago

I went back to older version

What version?

VasylenkoIhor commented 1 month ago

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

webmasterdevlin commented 2 weeks ago

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.

dillonrowan commented 2 weeks ago

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.

aweigor commented 23 hours ago

@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.