Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(#88): Adding an option for use local IP as host #116

Merged
merged 15 commits into from
May 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,9 @@
```

<hr>

* **`liveServer.settings.useLocalIp:`** : Use local IP as host.

* Default: `false`

<hr>
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@
"default": "127.0.0.1",
"description": "To switch between localhost or 127.0.0.1 or anything else. Default is 127.0.0.1"
},
"liveServer.settings.useLocalIp": {
"type": "boolean",
"default": false,
"description": "Use local IP as host"
},
"liveServer.settings.proxy": {
"type": "object",
"default": {
Expand Down Expand Up @@ -299,6 +304,7 @@
"dependencies": {
"http-proxy": "^1.16.2",
"http-shutdown": "^1.2.0",
"ips": "^2.1.3",
"live-server": "file:lib\\live-server",
"opn": "^5.3.0"
},
Expand Down
4 changes: 4 additions & 0 deletions src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export class Config {
return Config.getSettings<string>('host');
}

public static get getLocalIp(): string {
return Config.getSettings<string>('useLocalIp');
}

public static get getPort(): number {
return Config.getSettings<number>('port');
}
Expand Down
3 changes: 1 addition & 2 deletions src/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import { Config } from './Config';

export const SUPPRORTED_EXT: string[] = [
Expand Down Expand Up @@ -150,6 +151,4 @@ export class Helper {

return proxy;
}


}
7 changes: 5 additions & 2 deletions src/appModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@ import { Config } from './Config';
import { Helper, SUPPRORTED_EXT } from './Helper';

import * as opn from 'opn';
import * as ips from 'ips';

export class AppModel {

private IsServerRunning: boolean;
private IsStaging: boolean;
private LiveServerInstance;
private runningPort: number;
private localIps: any;

constructor() {
const _ips = ips();
this.localIps = _ips.local ? _ips.local : Config.getHost;
this.IsServerRunning = false;
this.runningPort = null;

this.HaveAnySupportedFile(() => {
StatusbarUi.Init();
});

}

public Golive(pathUri?: string) {
Expand Down Expand Up @@ -156,7 +159,7 @@ export class AppModel {
}

private openBrowser(port: number, path: string) {
const host = Config.getHost;
const host = Config.getLocalIp ? this.localIps : Config.getHost;
const protocol = Config.getHttps.enable ? 'https' : 'http';

let params: string[] = [];
Expand Down
1 change: 0 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export function activate(context: ExtensionContext) {
const appModel = new AppModel();

// checkNewAnnouncement(context.globalState);

context.subscriptions.push(commands
.registerCommand('extension.liveServer.goOnline', (fileUri) => {
workspace.saveAll().then(() => {
Expand Down