Updated mock-api to serve with a little delay. Also added possibility to change the delay

This commit is contained in:
Erik Tiekstra
2021-09-15 11:29:34 +02:00
parent b97f6e7dfb
commit a3944cf311
5 changed files with 106 additions and 2 deletions

1
.gitignore vendored
View File

@@ -42,3 +42,4 @@ Thumbs.db
mock-api/**/node_modules
mock-api/**/api.json
**VERSION.md
**temp.txt

View File

@@ -9,6 +9,8 @@
"version": "0.0.1",
"license": "MIT",
"dependencies": {
"command-line-args": "^5.2.0",
"connect-pause": "^0.1.1",
"faker": "^5.4.0",
"json-server": "^0.16.3"
}
@@ -84,6 +86,14 @@
"node": ">=8"
}
},
"node_modules/array-back": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/array-back/-/array-back-3.1.0.tgz",
"integrity": "sha512-TkuxA4UCOvxuDK6NZYXCalszEzj+TLszyASooky+i742l9TqsOdYCMJJupxRic61hwquNtppB3hgcuq9SVSH1Q==",
"engines": {
"node": ">=6"
}
},
"node_modules/array-flatten": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
@@ -268,6 +278,20 @@
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"node_modules/command-line-args": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/command-line-args/-/command-line-args-5.2.0.tgz",
"integrity": "sha512-4zqtU1hYsSJzcJBOcNZIbW5Fbk9BkjCp1pZVhQKoRaWL5J7N4XphDLwo8aWwdQpTugxwu+jf9u2ZhkXiqp5Z6A==",
"dependencies": {
"array-back": "^3.1.0",
"find-replace": "^3.0.0",
"lodash.camelcase": "^4.3.0",
"typical": "^4.0.0"
},
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/compressible": {
"version": "2.0.18",
"resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz",
@@ -587,6 +611,17 @@
"node": ">= 0.8"
}
},
"node_modules/find-replace": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/find-replace/-/find-replace-3.0.0.tgz",
"integrity": "sha512-6Tb2myMioCAgv5kfvP5/PkZZ/ntTpVK39fHY7WkWBgvbeE+VHd/tZuZ4mrC+bxh4cfOZeYKVPaJIZtZXV7GNCQ==",
"dependencies": {
"array-back": "^3.0.1"
},
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/forwarded": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
@@ -901,6 +936,11 @@
"node": ">= 4"
}
},
"node_modules/lodash.camelcase": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz",
"integrity": "sha1-soqmKIorn8ZRA1x3EfZathkDMaY="
},
"node_modules/lowdb": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/lowdb/-/lowdb-1.0.0.tgz",
@@ -1564,6 +1604,14 @@
"is-typedarray": "^1.0.0"
}
},
"node_modules/typical": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/typical/-/typical-4.0.0.tgz",
"integrity": "sha512-VAH4IvQ7BDFYglMd7BPRDfLgxZZX4O4TFcRDA6EN5X7erNJJq+McIEp8np9aVtxrCJ6qx4GTYVfOWNjcqwZgRw==",
"engines": {
"node": ">=8"
}
},
"node_modules/unique-string": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/unique-string/-/unique-string-2.0.0.tgz",
@@ -1796,6 +1844,11 @@
"color-convert": "^2.0.1"
}
},
"array-back": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/array-back/-/array-back-3.1.0.tgz",
"integrity": "sha512-TkuxA4UCOvxuDK6NZYXCalszEzj+TLszyASooky+i742l9TqsOdYCMJJupxRic61hwquNtppB3hgcuq9SVSH1Q=="
},
"array-flatten": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
@@ -1945,6 +1998,17 @@
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"command-line-args": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/command-line-args/-/command-line-args-5.2.0.tgz",
"integrity": "sha512-4zqtU1hYsSJzcJBOcNZIbW5Fbk9BkjCp1pZVhQKoRaWL5J7N4XphDLwo8aWwdQpTugxwu+jf9u2ZhkXiqp5Z6A==",
"requires": {
"array-back": "^3.1.0",
"find-replace": "^3.0.0",
"lodash.camelcase": "^4.3.0",
"typical": "^4.0.0"
}
},
"compressible": {
"version": "2.0.18",
"resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz",
@@ -2205,6 +2269,14 @@
"unpipe": "~1.0.0"
}
},
"find-replace": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/find-replace/-/find-replace-3.0.0.tgz",
"integrity": "sha512-6Tb2myMioCAgv5kfvP5/PkZZ/ntTpVK39fHY7WkWBgvbeE+VHd/tZuZ4mrC+bxh4cfOZeYKVPaJIZtZXV7GNCQ==",
"requires": {
"array-back": "^3.0.1"
}
},
"forwarded": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
@@ -2447,6 +2519,11 @@
"resolved": "https://registry.npmjs.org/lodash-id/-/lodash-id-0.14.0.tgz",
"integrity": "sha1-uvSJNOVDobXWNG+MhGmLGoyAOJY="
},
"lodash.camelcase": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz",
"integrity": "sha1-soqmKIorn8ZRA1x3EfZathkDMaY="
},
"lowdb": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/lowdb/-/lowdb-1.0.0.tgz",
@@ -2958,6 +3035,11 @@
"is-typedarray": "^1.0.0"
}
},
"typical": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/typical/-/typical-4.0.0.tgz",
"integrity": "sha512-VAH4IvQ7BDFYglMd7BPRDfLgxZZX4O4TFcRDA6EN5X7erNJJq+McIEp8np9aVtxrCJ6qx4GTYVfOWNjcqwZgRw=="
},
"unique-string": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/unique-string/-/unique-string-2.0.0.tgz",

View File

@@ -5,12 +5,14 @@
"scripts": {
"generate-api": "node ./scripts/generate-api.js",
"start": "npm run generate-api && node server.js",
"start:delay": "npm start -- --delay 500"
"start:delay": "npm start -- --delay 1000"
},
"author": "Erik Tiekstra (erik.tiekstra@arbetsformedlingen.se)",
"license": "MIT",
"type": "module",
"dependencies": {
"command-line-args": "^5.2.0",
"connect-pause": "^0.1.1",
"faker": "^5.4.0",
"json-server": "^0.16.3"
}

View File

@@ -1,9 +1,24 @@
import commandLineArgs from 'command-line-args';
import pause from 'connect-pause';
import jsonServer from 'json-server';
const optionDefinitions = [
{
name: 'delay',
description: 'Add a delay in ms to the server. Defaults to 200.',
alias: 'd',
type: Number,
defaultValue: 200,
},
];
const options = commandLineArgs(optionDefinitions);
const server = jsonServer.create();
const router = jsonServer.router('api.json');
const middlewares = jsonServer.defaults();
server.use(pause(options.delay));
server.use(middlewares);
server.use(

View File

@@ -35,7 +35,11 @@ version=${version:-$config}
# UPDATING VERSION
# ----------------------------------
echo -e "${CYAN}Setting version to ${version} inside environments.${config}.ts${NOCOLOR}"
if [ $config = "local" ]; then
sed "s/version:.*',/version: '${version}',/" apps/mina-sidor-fa/src/environments/environment.ts > temp.txt && mv temp.txt apps/mina-sidor-fa/src/environments/environment.ts
else
sed "s/version:.*',/version: '${version}',/" apps/mina-sidor-fa/src/environments/environment.$config.ts > temp.txt && mv temp.txt apps/mina-sidor-fa/src/environments/environment.$config.ts
fi
echo -e "${GREEN}Version set to ${version}${NOCOLOR}"
# ----------------------------------