Simplify proxy config (#17548)

Signed-off-by: AllForNothing <sshijun@vmware.com>

Signed-off-by: AllForNothing <sshijun@vmware.com>
This commit is contained in:
Shijun Sun 2022-09-22 11:40:04 +08:00 committed by GitHub
parent a686f30b01
commit 1f908088b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 67 additions and 111 deletions

View File

@ -11,6 +11,7 @@
],
"parserOptions": {
"project": [
"server/tsconfig.json",
"tsconfig.json",
"e2e/tsconfig.json"
],

View File

@ -14,97 +14,23 @@ Start
4. npm run start
5. open your browser on https://localhost:4200
```json
{
"/api/*": {
[
{
"context": [
"/api",
"/c",
"/i18n",
"/chartrepo",
"/LICENSE",
"/swagger.json",
"/swagger2.json",
"/devcenter-api-2.0",
"/swagger-ui.bundle.js"
],
"target": "https://hostname",
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
},
"/service/*": {
"target": "https://hostname",
"secure": false,
"logLevel": "debug"
},
"/c/login": {
"target": "https://hostname",
"secure": false,
"logLevel": "debug"
},
"/c/oidc/login": {
"target": "https://hostname",
"secure": false,
"logLevel": "debug"
},
"/sign_in": {
"target": "https://hostname",
"secure": false,
"logLevel": "debug"
},
"/c/log_out": {
"target": "https://hostname",
"secure": false,
"logLevel": "debug"
},
"/sendEmail": {
"target": "https://hostname",
"secure": false,
"logLevel": "debug"
},
"/language": {
"target": "https://hostname",
"secure": false,
"logLevel": "debug"
},
"/reset": {
"target": "https://hostname",
"secure": false,
"logLevel": "debug"
},
"/c/userExists": {
"target": "https://hostname",
"secure": false,
"logLevel": "debug"
},
"/reset_password": {
"target": "https://hostname",
"secure": false,
"logLevel": "debug"
},
"/i18n/lang/*.json": {
"target": "https://hostname",
"secure": false,
"logLevel": "debug"
},
"/chartrepo/*": {
"target": "https://hostname",
"secure": false,
"logLevel": "debug"
},
"/LICENSE": {
"target": "https://hostname",
"secure": false,
"logLevel": "debug"
},
"/swagger.json": {
"target": "https://hostname",
"secure": false,
"logLevel": "debug"
},
"/swagger2.json": {
"target": "https://hostname",
"secure": false,
"logLevel": "debug"
},
"/devcenter-api-2.0": {
"target": "https://hostname",
"secure": false,
"logLevel": "debug"
},
"/swagger-ui.bundle.js": {
"target": "https://hostname",
"secure": false,
"logLevel": "debug"
}
}
]
```

View File

@ -124,6 +124,7 @@
"builder": "@angular-eslint/builder:lint",
"options": {
"lintFilePatterns": [
"server/**/*.ts",
"src/**/*.ts",
"src/**/*.html"
]

View File

@ -14,7 +14,7 @@ suppose you want to mock a api server for below code:
1. Edit mock-api.ts, and add below code:
```typescript
mockApi.get('/api/scanners', Controllers.getScanner);
mockApi.get('/api/v2.0/scanners', Controllers.getScanner);
```
2. Add your method implementation into folder "controllers" and export it:
```typescript
@ -28,14 +28,39 @@ suppose you want to mock a api server for below code:
npm run mock-api-server
```
4.(Optional)Edit file proxy.config.json, and add below code on the top:
4.Edit the file proxy.config.json, and add a proxy object at the top as below:
```json
"/api/scanner": {
"target": "http://localhost:3000",
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
}
[
// redirect requests to the mocked api server
{
"context": [
"/api/v2.0/scanners"
],
"target": "http://localhost:3000",
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
},
// redirect requests to the back-end server
{
"context": [
"/api",
"/c",
"/i18n",
"/chartrepo",
"/LICENSE",
"/swagger.json",
"/swagger2.json",
"/devcenter-api-2.0",
"/swagger-ui.bundle.js"
],
"target": "https://hostname",
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
}
]
```
5.Now, you can get mocked scanners when you send "get request" to "/api/scanners"
5. Run `npm run start`, then all the mocked APIs will be redirected to the mocked server

View File

@ -1,10 +1,13 @@
import { Scanner } from '../../src/app/base/left-side-nav/interrogation-services/scanner/scanner';
import { Request, Response } from "express";
import { Request, Response } from 'express';
import { Scanner } from '../../ng-swagger-gen/models/scanner';
export function getScanner(req: Request, res: Response) {
const scanners: Scanner[] = [new Scanner(), new Scanner()];
res.json(scanners);
const scanners: Scanner[] = [
{
name: 'demo',
vendor: 'test',
version: '1.0',
},
];
res.json(scanners);
}

View File

@ -1,19 +1,19 @@
import express from "express";
import express from 'express';
import { Express } from 'express';
import * as Controllers from '../controllers';
import { CURRENT_BASE_HREF } from "../../src/app/shared/units/utils";
const mockApi: Express = express();
mockApi.get('/', (req, res) => {
res.send('Hello World!');
const CURRENT_BASE_HREF: string = '/api/v2.0';
mockApi.get('/', (req, res) => {
res.send('Hello World!');
});
mockApi.get(CURRENT_BASE_HREF + '/scanners', Controllers.getScanner);
mockApi.listen(3000, () => {
console.log('Api server listening on port 3000!');
mockApi.listen(3000, () => {
console.log('Api server listening on port 3000!');
});
export default mockApi;