harbor/src/portal/server
Will Sun 2d84b62fe2
Refactor UI routing and remove redundant code (#14166)
Signed-off-by: AllForNothing <sshijun@vmware.com>
2021-02-18 09:12:23 +08:00
..
controllers Refactor UI routing and remove redundant code (#14166) 2021-02-18 09:12:23 +08:00
src Refactor UI routing and remove redundant code (#14166) 2021-02-18 09:12:23 +08:00
README.md Add express module 2020-01-10 16:21:16 +08:00
tsconfig.json Add express module 2020-01-10 16:21:16 +08:00

README.md

Mocked Api-server based on "Node.js" + "Express" + "Typescript"

How to use?

suppose you want to mock a api server for below code:

     getScannersByName(name: string): Observable<Scanner[]> {
        name = encodeURIComponent(name);
        return this.http.get(`/api/scanners?ex_name=${name}`)
                .pipe(catchError(error => observableThrowError(error)))
                .pipe(map(response => response as Scanner[]));
    }
  1. Edit mock-api.ts, and add below code:
   mockApi.get('/api/scanners', Controllers.getScanner);
  1. Add your method implementation into folder "controllers" and export it:
    export function getScanner(req: Request, res: Response) {
      const scanners: Scanner[] =  [new Scanner(), new Scanner()];
      res.json(scanners);
    }

3.cd portal and run

  npm run mock-api-server

4.(Optional)Edit file proxy.config.json, and add below code on the top:

  "/api/scanner": {
  "target": "http://localhost:3000",
  "secure": false,
  "changeOrigin": true,
  "logLevel": "debug"
 }

5.Now, you can get mocked scanners when you send "get request" to "/api/scanners"