mock-config-server 2.0.0 → 2.0.1
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/dist/src/server/createMockServer/createMockServer.js +4 -3
- package/dist/src/static/staticMiddleware/staticMiddleware.js +5 -5
- package/dist/src/static/views/notFound.ejs +42 -0
- package/dist/src/utils/helpers/url/convertWin32PathToUnix/convertWin32PathToUnix.d.ts +1 -0
- package/dist/src/utils/helpers/url/convertWin32PathToUnix/convertWin32PathToUnix.js +8 -0
- package/dist/src/utils/helpers/url/index.d.ts +2 -0
- package/dist/src/utils/helpers/url/index.js +2 -0
- package/dist/src/utils/helpers/url/urlJoin/urlJoin.d.ts +1 -0
- package/dist/src/utils/helpers/url/urlJoin/urlJoin.js +14 -0
- package/package.json +4 -4
|
@@ -6,16 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.createMockServer = void 0;
|
|
7
7
|
const body_parser_1 = __importDefault(require("body-parser"));
|
|
8
8
|
const express_1 = __importDefault(require("express"));
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
9
|
const corsMiddleware_1 = require("../../cors/corsMiddleware/corsMiddleware");
|
|
11
10
|
const noCorsMiddleware_1 = require("../../cors/noCorsMiddleware/noCorsMiddleware");
|
|
12
11
|
const createGraphQLRoutes_1 = require("../../graphql/createGraphQLRoutes/createGraphQLRoutes");
|
|
13
12
|
const notFoundMiddleware_1 = require("../../notFound/notFoundMiddleware");
|
|
14
13
|
const createRestRoutes_1 = require("../../rest/createRestRoutes/createRestRoutes");
|
|
15
14
|
const staticMiddleware_1 = require("../../static/staticMiddleware/staticMiddleware");
|
|
15
|
+
const helpers_1 = require("../../utils/helpers");
|
|
16
16
|
const createMockServer = (mockServerConfig) => {
|
|
17
17
|
const { cors, staticPath, rest, graphql, interceptors } = mockServerConfig;
|
|
18
18
|
const server = (0, express_1.default)();
|
|
19
|
+
server.set('views', (0, helpers_1.urlJoin)(__dirname, '../../static/views'));
|
|
19
20
|
server.set('view engine', 'ejs');
|
|
20
21
|
server.use(body_parser_1.default.urlencoded({ extended: false }));
|
|
21
22
|
server.use(body_parser_1.default.json({ limit: '10mb' }));
|
|
@@ -31,12 +32,12 @@ const createMockServer = (mockServerConfig) => {
|
|
|
31
32
|
}
|
|
32
33
|
if (rest) {
|
|
33
34
|
const routerWithRestRoutes = (0, createRestRoutes_1.createRestRoutes)(express_1.default.Router(), rest.configs, interceptors);
|
|
34
|
-
const restBaseUrl =
|
|
35
|
+
const restBaseUrl = (0, helpers_1.urlJoin)(baseUrl, rest.baseUrl ?? '/');
|
|
35
36
|
server.use(restBaseUrl, routerWithRestRoutes);
|
|
36
37
|
}
|
|
37
38
|
if (graphql) {
|
|
38
39
|
const routerWithGraphQLRoutes = (0, createGraphQLRoutes_1.createGraphQLRoutes)(express_1.default.Router(), graphql.configs, interceptors);
|
|
39
|
-
const graphqlBaseUrl =
|
|
40
|
+
const graphqlBaseUrl = (0, helpers_1.urlJoin)(baseUrl, graphql.baseUrl ?? '/');
|
|
40
41
|
server.use(graphqlBaseUrl, routerWithGraphQLRoutes);
|
|
41
42
|
}
|
|
42
43
|
(0, notFoundMiddleware_1.notFoundMiddleware)({
|
|
@@ -5,26 +5,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.staticMiddleware = void 0;
|
|
7
7
|
const express_1 = __importDefault(require("express"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
8
|
const constants_1 = require("../../utils/constants");
|
|
9
|
+
const helpers_1 = require("../../utils/helpers");
|
|
10
10
|
const staticMiddleware = (server, baseUrl, staticPath) => {
|
|
11
11
|
const isStaticPathArray = Array.isArray(staticPath);
|
|
12
12
|
if (isStaticPathArray) {
|
|
13
13
|
staticPath.forEach((staticPath) => {
|
|
14
14
|
const isPathObject = typeof staticPath === 'object';
|
|
15
15
|
if (isPathObject) {
|
|
16
|
-
server.use(
|
|
16
|
+
server.use((0, helpers_1.urlJoin)(baseUrl, staticPath.prefix), express_1.default.static((0, helpers_1.urlJoin)(constants_1.APP_PATH, staticPath.path)));
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
|
-
server.use(baseUrl, express_1.default.static(
|
|
19
|
+
server.use(baseUrl, express_1.default.static((0, helpers_1.urlJoin)(constants_1.APP_PATH, staticPath)));
|
|
20
20
|
});
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
const isStaticPathObject = typeof staticPath === 'object';
|
|
24
24
|
if (isStaticPathObject) {
|
|
25
|
-
server.use(
|
|
25
|
+
server.use((0, helpers_1.urlJoin)(baseUrl, staticPath.prefix), express_1.default.static((0, helpers_1.urlJoin)(constants_1.APP_PATH, staticPath.path)));
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
server.use(baseUrl, express_1.default.static(
|
|
28
|
+
server.use(baseUrl, express_1.default.static((0, helpers_1.urlJoin)(constants_1.APP_PATH, staticPath)));
|
|
29
29
|
};
|
|
30
30
|
exports.staticMiddleware = staticMiddleware;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<body class="container">
|
|
4
|
+
<h1>404</h1>
|
|
5
|
+
<div>
|
|
6
|
+
Seems to be your config does not have data for '<%= requestMethod %>
|
|
7
|
+
<%= decodeURIComponent(url) %> request, or you have typo in it.
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<% if (restUrlSuggestions.length || graphqlUrlSuggestions.length) { %>
|
|
11
|
+
<h2>
|
|
12
|
+
Maybe you are looking for one of these paths?
|
|
13
|
+
</h2>
|
|
14
|
+
<% } %>
|
|
15
|
+
|
|
16
|
+
<% if (restUrlSuggestions.length) { %>
|
|
17
|
+
<div>
|
|
18
|
+
<h3>REST</h3>
|
|
19
|
+
<ul>
|
|
20
|
+
<% restUrlSuggestions.forEach((restUrlSuggestion) => { %>
|
|
21
|
+
<li>
|
|
22
|
+
<a href=<%= restUrlSuggestion %>><%= decodeURIComponent(restUrlSuggestion) %></a>
|
|
23
|
+
</li>
|
|
24
|
+
<% }) %>
|
|
25
|
+
</ul>
|
|
26
|
+
</div>
|
|
27
|
+
<% } %>
|
|
28
|
+
|
|
29
|
+
<% if (graphqlUrlSuggestions.length) { %>
|
|
30
|
+
<div>
|
|
31
|
+
<h3>GraphQL</h3>
|
|
32
|
+
<ul>
|
|
33
|
+
<% graphqlUrlSuggestions.forEach((graphqlUrlSuggestion) => { %>
|
|
34
|
+
<li>
|
|
35
|
+
<%= decodeURIComponent(graphqlUrlSuggestion) %>
|
|
36
|
+
</li>
|
|
37
|
+
<% }) %>
|
|
38
|
+
</ul>
|
|
39
|
+
</div>
|
|
40
|
+
<% } %>
|
|
41
|
+
</body>
|
|
42
|
+
</html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const convertWin32PathToUnix: (win32Path: string) => string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertWin32PathToUnix = void 0;
|
|
4
|
+
const convertWin32PathToUnix = (win32Path) => win32Path
|
|
5
|
+
.replace(/^\\\\\?\\/, '')
|
|
6
|
+
.replace(/\\/g, '/')
|
|
7
|
+
.replace(/\/\/+/g, '/');
|
|
8
|
+
exports.convertWin32PathToUnix = convertWin32PathToUnix;
|
|
@@ -16,3 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./getUrlParts/getUrlParts"), exports);
|
|
18
18
|
__exportStar(require("./removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes"), exports);
|
|
19
|
+
__exportStar(require("./urlJoin/urlJoin"), exports);
|
|
20
|
+
__exportStar(require("./convertWin32PathToUnix/convertWin32PathToUnix"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const urlJoin: (...paths: string[]) => string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.urlJoin = void 0;
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const convertWin32PathToUnix_1 = require("../convertWin32PathToUnix/convertWin32PathToUnix");
|
|
10
|
+
const urlJoin = (...paths) => {
|
|
11
|
+
const pathsToJoin = os_1.default.platform() === 'win32' ? paths.map((path) => (0, convertWin32PathToUnix_1.convertWin32PathToUnix)(path)) : paths;
|
|
12
|
+
return path_1.default.posix.join(...pathsToJoin);
|
|
13
|
+
};
|
|
14
|
+
exports.urlJoin = urlJoin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mock-config-server",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Tool that easily and quickly imitates server operation, create full fake api in few steps",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "SIBERIA CAN CODE 🧊",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"node": ">=14"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
|
-
"build": "
|
|
36
|
+
"build": "shx rm -rf dist && tsc -p tsconfig.production.json && shx cp -R src/static/views dist/src/static",
|
|
37
37
|
"prepare": "yarn build",
|
|
38
38
|
"test": "jest",
|
|
39
39
|
"lint": "eslint . --ext ts --no-error-on-unmatched-pattern",
|
|
@@ -57,7 +57,8 @@
|
|
|
57
57
|
"esbuild": "^0.17.8",
|
|
58
58
|
"express": "^4.18.1",
|
|
59
59
|
"flat": "^5.0.2",
|
|
60
|
-
"graphql": "^16.6.0"
|
|
60
|
+
"graphql": "^16.6.0",
|
|
61
|
+
"shx": "^0.3.4"
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|
|
63
64
|
"@types/jest": "^29.4.0",
|
|
@@ -77,7 +78,6 @@
|
|
|
77
78
|
"lint-staged": "^13.1.1",
|
|
78
79
|
"nodemon": "^2.0.19",
|
|
79
80
|
"prettier": "^2.8.3",
|
|
80
|
-
"rimraf": "4.1.2",
|
|
81
81
|
"supertest": "^6.3.3",
|
|
82
82
|
"ts-jest": "^29.0.3",
|
|
83
83
|
"typescript": "^4.9.5"
|