Skip to content

Commit

Permalink
Support customize server host
Browse files Browse the repository at this point in the history
  • Loading branch information
thinh committed Dec 10, 2018
1 parent 4265b62 commit 93a7493
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ OR

Default port of the preview url can be changed by changing the `swaggerViewer.defaultPort` value in `User/Workspace Settings`

### Change Default Host

Default host(localhost) of the preview url can be changed by changing the `swaggerViewer.defaultHost` value in `User/Workspace Settings`

## Validation (Partial)

Swagger Viewer validates your documents against Swagger 2.0 and OpenAPI specifications. If there are any issues it will be shown as a warning in the problems panel. Right now only one validation error will be shown even if there are multiple issues.
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
"type": "object",
"title": "Swagger Viewer configuration",
"properties": {
"swaggerViewer.defaultHost": {
"type": "string",
"default": "localhost",
"description": "Default host in which the preview should be opened."
},
"swaggerViewer.defaultPort": {
"type": "integer",
"default": 9000,
Expand Down
7 changes: 5 additions & 2 deletions src/preview/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import * as express from 'express';
import * as http from 'http';
import * as socketio from 'socket.io';

const SERVER_HOST = vscode.workspace.getConfiguration('swaggerViewer').defaultHost || 'localhost';

const SERVER_PORT = vscode.workspace.getConfiguration('swaggerViewer').defaultPort || 9000;

const FILE_CONTENT: { [key: string]: any } = {};

export class PreviewServer {

currentHost: string = SERVER_HOST
currentPort: number = SERVER_PORT
io: socketio.Server
server: http.Server
Expand Down Expand Up @@ -65,11 +68,11 @@ export class PreviewServer {
}

getUrl(fileHash: string): string {
return `http://localhost:${this.currentPort}/${fileHash}`;
return `http://${this.currentHost}:${this.currentPort}/${fileHash}`;
}

stop(){
this.server.close();
}

}
}

0 comments on commit 93a7493

Please sign in to comment.