typescript-mock-server 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/package.json +6 -6
- package/src/command-line.ts +0 -1
- package/src/impl/typescript-mock-server-impl.ts +10 -1
- package/src/models/config.ts +8 -0
- package/tms-models/users/get.ts +9 -0
- package/tsconfig.json +1 -1
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-mock-server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "Simple mock server that can be used in front end development. Instead of creating json files you can just publish TypeScript objects as json",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
"prettier": "^2.6.2"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@types/express": "^4.17.
|
|
36
|
-
"@types/node": "^
|
|
37
|
-
"express": "^4.
|
|
38
|
-
"ts-node-dev": "
|
|
35
|
+
"@types/express": "^4.17.13",
|
|
36
|
+
"@types/node": "^18.0.5",
|
|
37
|
+
"express": "^4.18.1",
|
|
38
|
+
"ts-node-dev": "2.0.0",
|
|
39
39
|
"tslog": "^3.3.3",
|
|
40
|
-
"typescript": "^4.
|
|
40
|
+
"typescript": "^4.7.4"
|
|
41
41
|
},
|
|
42
42
|
"prettier": {
|
|
43
43
|
"arrowParens": "avoid",
|
package/src/command-line.ts
CHANGED
|
@@ -53,7 +53,16 @@ export class TypescriptMockServerImpl implements TypescriptMockServer{
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
private addEndpoint(endpoint: string, httpVerb: HttpVerb, model: any) {
|
|
56
|
-
this.app[httpVerb](endpoint, (req, res) =>
|
|
56
|
+
this.app[httpVerb](endpoint, (req, res) => {
|
|
57
|
+
if (model?.config?.server?.statusCode) {
|
|
58
|
+
res.statusCode = model?.config?.server?.statusCode;
|
|
59
|
+
}
|
|
60
|
+
if (model?.config?.server?.delay) {
|
|
61
|
+
setTimeout(() => res.send(model.data), model?.config?.server?.delay);
|
|
62
|
+
} else {
|
|
63
|
+
return res.send(model.data);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
57
66
|
}
|
|
58
67
|
|
|
59
68
|
private handleRequest(path: string, dirent: Dirent, httpVerb: HttpVerb) {
|
package/tms-models/users/get.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Config } from '../../src/models/config';
|
|
2
|
+
|
|
1
3
|
export interface User {
|
|
2
4
|
id: number;
|
|
3
5
|
firstName: string;
|
|
@@ -18,3 +20,10 @@ export const data: User[] = [{
|
|
|
18
20
|
lastName: 'Development',
|
|
19
21
|
creationDate: newDate()
|
|
20
22
|
}];
|
|
23
|
+
|
|
24
|
+
export const config: Config = {
|
|
25
|
+
server: {
|
|
26
|
+
delay: 2000,
|
|
27
|
+
statusCode: 418
|
|
28
|
+
}
|
|
29
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
3
|
+
"target": "es6", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
4
4
|
|
|
5
5
|
"module": "commonjs", /* Specify what module code is generated. */
|
|
6
6
|
|