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

mod to make it actually run any html or other file type in local webserver and browser. #5

Open
visualperception opened this issue Aug 26, 2016 · 0 comments

Comments

@visualperception
Copy link

visualperception commented Aug 26, 2016

I edited extension.js locally because it doesn't work on my setup. You are not sending to the browser using http protocol so file is not rendered as a web page.

I have apache root folder as g:/xxx/ and each website is in a subfolder of the apache root folder.

in vscode I open a root folder of any particular website I want to edit and then I want to send that websites index.php to the browser.

So each of my websites is in its own root folder

g:/xxx/rootfolder

I have also taken out the file type check so I can send any file type to browser, PHP,ASP,HTM,HTML etc

my code for extension js is now as follows:

'use strict';
var vscode = require('vscode');
var path = require("path");
var open = require('open');
function activate(context) {
    var disposable = vscode.commands.registerCommand('extension.viewInBrowser', function () {
        var editor = vscode.window.activeTextEditor;
        if (!editor) {
            vscode.window.showWarningMessage('no active text editor!');
            return;
        }
        var file = editor.document.fileName;
        var ext = path.extname(file);
        var fileUrl = file.replace(/g:(\\|\/)xxx/g, ""); 
        open("http://localhost" + fileUrl);
    });
    context.subscriptions.push(disposable);
}
exports.activate = activate;
function deactivate() {
}
exports.deactivate = deactivate;
//# sourceMappingURL=extension.js.map

If anyone wants to use this code all you need to do is edit the regex to strip off the path to your webserver root (not your website root folder unless its the same).

i.e. replace
/g:(\\|\/)xxx/g
with:
/drive:(\\|\/)path-to-webserver-root/g

works for me, YMMV

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant