Running "json-server --watch ./data/db.json --port 8000 --routes ./data/routes.json" results in the error "Unknown option '--routes'"
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
The documentation says --routes is an option but the package in npm does not contain it?
afaik this option is not available in 1.0.0
The documentation for --routes only refers to 0.x.x releases
Will this option be available in the final v1 version?
How else can we make API routes that are level 2 or deeper? For example /api/users ?
I went back to older version
It doesn't make sense to remove a feature after it's been out?
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.
I went back to older version
What version?
I downgraded to the latest stable version (0.17.4) and I still see the error message “Unknown option ‘--routes’”.
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.
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 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.
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
...
@typicode please bump @tinyhttp/app to v2.4, it should be fixed now
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
npm remove json-server npm install [email protected] npx json-server --watch db.json --routes routes.json --port 8089
realmente essa solução funciona:
What a casual way to share this information.