Skip to content

Commit 65b32ca

Browse files
committed
feat: migrate to node v18.15, json-server v0.17.3, new faker.js
1 parent 2e60b75 commit 65b32ca

File tree

8 files changed

+10242
-25799
lines changed

8 files changed

+10242
-25799
lines changed

.github/workflows/validate.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v1
10+
- uses: actions/checkout@v3
1111

12-
- uses: actions/setup-node@v1
12+
- uses: actions/setup-node@v3
1313
with:
14-
node-version: 12.x
14+
node-version-file: .nvmrc
1515

1616
- name: install dependencies
1717
run: npm ci

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v18.15.0

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
FROM node:14.15-slim
1+
FROM node:18.15.0-slim
22

33
RUN mkdir /app
44
WORKDIR /app
55

6-
ENV JSON_SERVER_VERSION=0.16.3
6+
ENV JSON_SERVER_VERSION=0.17.3
77

88
RUN npm install -g json-server@${JSON_SERVER_VERSION}
99
COPY package.json package-lock.json ./

README.md

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ cd json-server-docker
5151
docker-compose up -d
5252
```
5353

54-
I highly recommend installing [`dotdocker`](https://github.com/aj-may/dotdocker) first. The
55-
container will then be accessible at <http://json-server.docker>.
54+
Visit <http://localhost:9999/> to see your running JSON Server.
55+
56+
If you have [`dotdocker`](https://github.com/aj-may/dotdocker) installed the server will also be
57+
accessible at <http://json-server.docker>.
5658

5759
### Options
5860

@@ -109,22 +111,22 @@ services:
109111
## Database File
110112
111113
When building your mock api's you'll most like want to generate some fake data and return a number
112-
of items for a specific collection. I've included [Lodash](https://lodash.com/) &
113-
[faker.js](https://github.com/Marak/faker.js) in the image to help facilitate doing these sorts of
114-
things inside your source file, or middleware for that matter. Here's an example of what I mean:
114+
of items for a specific collection. [Faker](https://github.com/faker-js/faker) is included in the
115+
image to help facilitate doing these sorts of things inside your db or middleware files. For
116+
example:
115117
116118
```js
117-
const faker = require('faker');
118-
const times = require('lodash/times');
119-
const startCase = require('lodash/startCase');
119+
const faker = require('@faker-js/faker');
120120

121121
module.exports = () => ({
122-
posts: times(100, index => ({
123-
id: index,
124-
title: startCase(faker.lorem.words(3)),
125-
body: faker.lorem.paragraphs(3),
126-
// and so on...
127-
})),
122+
posts: faker.helpers.multiple(
123+
() => ({
124+
id: faker.datatype.uuid(),
125+
title: faker.lorem.words(3),
126+
body: faker.lorem.paragraphs(3),
127+
}),
128+
{ count: 100 },
129+
),
128130
});
129131
```
130132

@@ -159,9 +161,3 @@ feature change with our implementation but the `json-server` version doesn't cha
159161
```sh
160162
git tag -fa v0.16.1 -m "Update v0.16.1 tag" && git push origin v0.16.1 --force
161163
```
162-
163-
Docker Hub is configured to automatically build on new tags pushed to GitHub.
164-
165-
## Todo
166-
167-
- Add examples of using this with docker cli, without a compose file

db.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
const { faker } = require('@faker-js/faker');
2+
13
/**
24
* This is a the main database file. It's meant to be mounted over.
35
*/
46
module.exports = () => ({
5-
posts: [{ id: 10, title: 'json-server', author: 'typicode' }],
7+
posts: faker.helpers.multiple(
8+
() => ({
9+
id: faker.datatype.uuid(),
10+
title: faker.lorem.words(3),
11+
body: faker.lorem.paragraphs(3),
12+
}),
13+
{ count: 100 },
14+
),
615
comments: [{ id: 1, body: 'some comment', postId: 1 }],
716
profile: { name: 'typicode' },
817
});

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ services:
88
- ./db.js:/app/db.js
99
- ./routes.json:/app/routes.json:delegated
1010
- ./middleware.js:/app/middleware.js:delegated
11+
ports:
12+
- 9999:80
1113
environment:
1214
VIRTUAL_HOST: json-server.docker

0 commit comments

Comments
 (0)