1
1
# json-server-docker
2
2
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 .
5
5
6
6
[ ![ version] ( https://img.shields.io/docker/v/codfish/json-server/0.17.3 )] ( https://hub.docker.com/r/codfish/json-server )
7
7
[ ![ 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
43
43
[ ` jwt-decode ` ] ( https://github.com/auth0/jwt-decode ) in any of the files powering your mock api.
44
44
- 🧳 ** Install your own dependencies** - Use the ` DEPENDENCIES ` envvar to pass a list of additional
45
45
npm dependencies to use in your server files.
46
+ - 🔂 ** Hot reloading** the server on any changes.
46
47
47
48
## Getting Started
48
49
@@ -52,7 +53,7 @@ Docker image for building a full fake REST API with
52
53
> image, which might break. Image tags are based off of the
53
54
> [ release versions for json-server] ( https://github.com/typicode/json-server/releases ) . However
54
55
> 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 ) .
56
57
57
58
By default, the image runs an instance of ` json-server ` with some dummy data for show. Spin up the
58
59
example mock api in seconds.
@@ -89,7 +90,6 @@ version: '3'
89
90
services :
90
91
api :
91
92
image : codfish/json-server:0.17.3
92
- command : npm run dev
93
93
ports :
94
94
- 9999:80
95
95
volumes :
@@ -98,7 +98,7 @@ services:
98
98
- ./my-routes.json:/app/routes.json:delegated
99
99
` ` `
100
100
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 .
102
102
103
103
# ## Docker cli
104
104
@@ -107,18 +107,17 @@ docker run -d -p 9999:80 \
107
107
-v ./my-db.js:/app/db.js \
108
108
-v ./my-middleware.js:/app/middleware.json \
109
109
-v ./my-routes.json:/app/routes.json \
110
- codfish/json-server:0.17.3 npm run dev
110
+ codfish/json-server:0.17.3
111
111
` ` `
112
112
113
113
# ## Advanced
114
114
115
- Set configuration
115
+ Set configuration via environment variables.
116
116
117
117
` ` ` yaml
118
118
services:
119
119
json-server:
120
120
image: codfish/json-server:0.17.3
121
- command: npm run dev
122
121
volumes:
123
122
- ./db.ts:/app/db.ts:delegated
124
123
- ./middleware.ts:/app/middleware.ts:delegated
@@ -152,8 +151,6 @@ See all the [available options below](#options).
152
151
- ` /app/routes.json` - Custom
153
152
[routes file](https://github.com/typicode/json-server#add-custom-routes).
154
153
- ` /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.
157
154
158
155
# # Database File
159
156
@@ -291,19 +288,19 @@ upper snake-case (i.e. `--no-cors` -> `NO_CORS`).
291
288
292
289
` ⋆` = Custom option. Not an official `json-server` option.
293
290
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" |
307
304
| ⋆ `DEPENDENCIES` | Install extra npm dependencies in the container for you to use in your server files. | — |
308
305
309
306
For details on the options
0 commit comments