typescript-mock-server 1.0.4 → 1.0.6
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
CHANGED
|
@@ -5,7 +5,7 @@ have to update your mock, otherwise you will receive compile errors.
|
|
|
5
5
|
|
|
6
6
|
# Quickstart
|
|
7
7
|
The easiest way to check out this stub/mock server is by installing it as a (dev)dependency and then
|
|
8
|
-
add a script to you scripts section: `npm run --prefix node_modules/typescript-mock-server start -- --path
|
|
8
|
+
add a script to you scripts section: `npm run --prefix node_modules/typescript-mock-server start -- --path=$INIT_CWD/tms-models`.
|
|
9
9
|
Your models should export a data const and your file should be named as `^(get|post){1}(-\d)?.ts$`.
|
|
10
10
|
Changes are being picked up automatically, so no need for a restart. When you add files, you have to restart.
|
|
11
11
|
|
|
@@ -14,6 +14,7 @@ Check out the [working example project](https://github.com/GuyT07/typescript-moc
|
|
|
14
14
|
# Options
|
|
15
15
|
- `--port=x`: Port number the server runs on
|
|
16
16
|
- `--path=x`: Path to your models
|
|
17
|
+
- `--cors=http://localhost:5000`: Set Access-Control-Allow-Origin header, leave empty to accept all
|
|
17
18
|
|
|
18
19
|
## Register mocks/stubs
|
|
19
20
|
Examples talk, so lets start with an example.
|
|
@@ -90,6 +91,8 @@ Following dependencies are being used:
|
|
|
90
91
|
|
|
91
92
|
|
|
92
93
|
## Release notes (will be moved to GitHub in the future)
|
|
94
|
+
- v1.0.6 - Bugfix: accidentally included "npm" and "install" dependency, removed again
|
|
95
|
+
- v1.0.5 - Set $INIT_CWD to support all platforms and add CORS option
|
|
93
96
|
- v1.0.3 - Updated README to include delay interval example
|
|
94
97
|
- v1.0.2 - Use correct command to push tags
|
|
95
98
|
- v1.0.1 - Include correct files in GIT tag
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-mock-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
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",
|
|
7
|
-
"example": "ts-node-dev src/index.ts --path=$INIT_CWD/tms-models --port=5000",
|
|
7
|
+
"example": "ts-node-dev src/index.ts --path=$INIT_CWD/tms-models --port=5000 --cors=http://localhost:5000",
|
|
8
8
|
"start": "ts-node-dev src/index.ts",
|
|
9
9
|
"update-deps": "npm update",
|
|
10
10
|
"get-version": "echo $npm_package_version",
|
|
@@ -30,11 +30,13 @@
|
|
|
30
30
|
"url": "https://genydev.nl"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
+
"@types/cors": "^2.8.12",
|
|
33
34
|
"prettier": "^2.6.2"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
37
|
"@types/express": "^4.17.13",
|
|
37
38
|
"@types/node": "^18.0.5",
|
|
39
|
+
"cors": "^2.8.5",
|
|
38
40
|
"express": "^4.18.1",
|
|
39
41
|
"ts-node-dev": "2.0.0",
|
|
40
42
|
"tslog": "^3.3.3",
|
package/src/command-line.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import express, { Express } from 'express';
|
|
2
|
+
import cors, { CorsOptions } from 'cors';
|
|
2
3
|
import { CommandLineImpl } from './command-line-impl';
|
|
3
4
|
import { Command, CommandLine } from '../command-line';
|
|
4
5
|
import { RegisteredEndpoint } from '../models/registered-endpoint';
|
|
@@ -31,6 +32,11 @@ export class TypescriptMockServerImpl implements TypescriptMockServer{
|
|
|
31
32
|
this.log.info(`basePath: ${this.basePath}`);
|
|
32
33
|
this.readRoutes(this.basePath).catch(error => this.log.error(error));
|
|
33
34
|
const port = this.commandLine.getCommand(Command.PORT) || 3000;
|
|
35
|
+
const corsSetting: CorsOptions = {
|
|
36
|
+
origin: this.commandLine.getCommand(Command.CORS) || '*'
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
this.app.use(cors(corsSetting))
|
|
34
40
|
this.app.listen(port, () => {
|
|
35
41
|
this.log.info(`App is listening on port ${port}!`);
|
|
36
42
|
});
|
|
@@ -100,6 +106,6 @@ export class TypescriptMockServerImpl implements TypescriptMockServer{
|
|
|
100
106
|
this.log.warn(`Path parameter not set, fallback to default tms-models`);
|
|
101
107
|
return 'tms-models';
|
|
102
108
|
}
|
|
103
|
-
return
|
|
109
|
+
return this.commandLine.getCommand(Command.PATH)!!;
|
|
104
110
|
}
|
|
105
111
|
}
|