11# json-server-docker
22
3- Docker image for building a full fake REST API with
4- [ json-server ] ( https://github.com/typicode/json-server ) .
3+ Dockerized [ json-server ] ( https://github.com/typicode/json-server ) for building a full fake RESTful
4+ API .
55
66[ ![ version] ( https://img.shields.io/docker/v/codfish/json-server/0.17.3 )] ( https://hub.docker.com/r/codfish/json-server )
77[ ![ pulls] ( https://img.shields.io/docker/pulls/codfish/json-server.svg )] ( https://hub.docker.com/r/codfish/json-server )
@@ -43,6 +43,7 @@ Docker image for building a full fake REST API with
4343 [ ` jwt-decode ` ] ( https://github.com/auth0/jwt-decode ) in any of the files powering your mock api.
4444- 🧳 ** Install your own dependencies** - Use the ` DEPENDENCIES ` envvar to pass a list of additional
4545 npm dependencies to use in your server files.
46+ - 🔂 ** Hot reloading** the server on any changes.
4647
4748## Getting Started
4849
@@ -52,7 +53,7 @@ Docker image for building a full fake REST API with
5253> image, which might break. Image tags are based off of the
5354> [ release versions for json-server] ( https://github.com/typicode/json-server/releases ) . However
5455> there is not an image for every version. See the available versions
55- > [ here] ( https://hub.docker.com/r/codfish/json-server ) .
56+ > [ here] ( https://hub.docker.com/r/codfish/json-server/tags ) .
5657
5758By default, the image runs an instance of ` json-server ` with some dummy data for show. Spin up the
5859example mock api in seconds.
@@ -89,7 +90,6 @@ version: '3'
8990services :
9091 api :
9192 image : codfish/json-server:0.17.3
92- command : npm run dev
9393 ports :
9494 - 9999:80
9595 volumes :
@@ -98,7 +98,7 @@ services:
9898 - ./my-routes.json:/app/routes.json:delegated
9999` ` `
100100
101- Run ` docker-compose up api`. Visit <http://localhost:9999/> to see your running JSON Server .
101+ Run ` docker-compose up api`. Visit <http://localhost:9999/> to see your API .
102102
103103# ## Docker cli
104104
@@ -107,18 +107,17 @@ docker run -d -p 9999:80 \
107107 -v ./my-db.js:/app/db.js \
108108 -v ./my-middleware.js:/app/middleware.json \
109109 -v ./my-routes.json:/app/routes.json \
110- codfish/json-server:0.17.3 npm run dev
110+ codfish/json-server:0.17.3
111111` ` `
112112
113113# ## Advanced
114114
115- Set configuration
115+ Set configuration via environment variables.
116116
117117` ` ` yaml
118118services:
119119 json-server:
120120 image: codfish/json-server:0.17.3
121- command: npm run dev
122121 volumes:
123122 - ./db.ts:/app/db.ts:delegated
124123 - ./middleware.ts:/app/middleware.ts:delegated
@@ -152,8 +151,6 @@ See all the [available options below](#options).
152151 - ` /app/routes.json` - Custom
153152 [routes file](https://github.com/typicode/json-server#add-custom-routes).
154153 - ` /public` - Static files directory.
155- - Use `npm run dev` as the Docker `command` to enable hot reloading the server on any changes to
156- mounted files.
157154
158155# # Database File
159156
@@ -291,19 +288,19 @@ upper snake-case (i.e. `--no-cors` -> `NO_CORS`).
291288
292289` ⋆` = Custom option. Not an official `json-server` option.
293290
294- | Option | Description | Default |
295- | -------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------- |
296- | `MIDDLEWARES` | Path to middleware file | `middleware.js` (Stored in image, optionally mount over it or provide your own) |
297- | `CONFIG` | Path to config file | Defers to `json-server` default |
298- | `SNAPSHOTS` | Set snapshots directory | Defers to `json-server` default |
299- | `ID` | Set database id property (e.g. `address`) | Defers to `json-server` default |
300- | `FKS` | Set foreign key suffix, (e.g. `_id` as in `user_id`) | Defers to `json-server` default |
301- | `DELAY` | Add delay to responses (ms) | — |
302- | `STATIC` | Set static files directory | Defers to `json-server` default |
303- | `QUIET` | Suppress log messages from output | Boolean flag only true if set to "true" |
304- | `NO_GZIP` | Disable GZIP Content-Encoding | Boolean flag only true if set to "true" |
305- | `NO_CORS` | Disable Cross-Origin Resource Sharing | Boolean flag only true if set to "true" |
306- | `READ_ONLY` | Allow only GET requests | Boolean flag only true if set to "true" |
291+ | Option | Description | Default |
292+ | ---------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------- |
293+ | `MIDDLEWARES` | Path to middleware file | `middleware.js` (Stored in image, optionally mount over it or provide your own) |
294+ | `CONFIG` | Path to config file | Defers to `json-server` default |
295+ | `SNAPSHOTS` | Set snapshots directory | Defers to `json-server` default |
296+ | `ID` | Set database id property (e.g. `address`) | Defers to `json-server` default |
297+ | `FKS` | Set foreign key suffix, (e.g. `_id` as in `user_id`) | Defers to `json-server` default |
298+ | `DELAY` | Add delay to responses (ms) | — |
299+ | `STATIC` | Set static files directory | Defers to `json-server` default |
300+ | `QUIET` | Suppress log messages from output | Boolean flag only true if set to "true" |
301+ | `NO_GZIP` | Disable GZIP Content-Encoding | Boolean flag only true if set to "true" |
302+ | `NO_CORS` | Disable Cross-Origin Resource Sharing | Boolean flag only true if set to "true" |
303+ | `READ_ONLY` | Allow only GET requests | Boolean flag only true if set to "true" |
307304| ⋆ `DEPENDENCIES` | Install extra npm dependencies in the container for you to use in your server files. | — |
308305
309306For details on the options
0 commit comments