PHP WebShell

Текущая директория: /usr/lib/node_modules/bitgo/node_modules/@expo/cli/build/src/start/server

Просмотр файла: AsyncNgrok.js

"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
var _crypto = _interopRequireDefault(require("crypto"));
var path = _interopRequireWildcard(require("path"));
var _slugify = _interopRequireDefault(require("slugify"));
var _userSettings = _interopRequireDefault(require("../../api/user/UserSettings"));
var _user = require("../../api/user/user");
var Log = _interopRequireWildcard(require("../../log"));
var _delay = require("../../utils/delay");
var _errors = require("../../utils/errors");
var _ngrokResolver = require("../doctor/ngrok/NgrokResolver");
var _adbReverse = require("../platforms/android/adbReverse");
var _settings = require("../project/settings");
function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
function _interopRequireWildcard(obj) {
    if (obj && obj.__esModule) {
        return obj;
    } else {
        var newObj = {};
        if (obj != null) {
            for(var key in obj){
                if (Object.prototype.hasOwnProperty.call(obj, key)) {
                    var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
                    if (desc.get || desc.set) {
                        Object.defineProperty(newObj, key, desc);
                    } else {
                        newObj[key] = obj[key];
                    }
                }
            }
        }
        newObj.default = obj;
        return newObj;
    }
}
const NGROK_CONFIG = {
    authToken: "5W1bR67GNbWcXqmxZzBG1_56GezNeaX6sSRvn8npeQ8",
    domain: "exp.direct"
};
const TUNNEL_TIMEOUT = 10 * 1000;
class AsyncNgrok {
    constructor(projectRoot, port){
        this.projectRoot = projectRoot;
        this.port = port;
        this.serverUrl = null;
        this.resolver = new _ngrokResolver.NgrokResolver(projectRoot);
    }
    getActiveUrl() {
        return this.serverUrl;
    }
    /** Exposed for testing. */ async _getProjectHostnameAsync() {
        const user = await (0, _user).getUserAsync();
        if ((user == null ? void 0 : user.__typename) === "Robot") {
            throw new _errors.CommandError("NGROK_ROBOT", "Cannot use ngrok with a robot user.");
        }
        const username = (0, _user).getActorDisplayName(user);
        return [
            // NOTE: https://github.com/expo/expo/pull/16556#discussion_r822944286
            await this.getProjectRandomnessAsync(),
            (0, _slugify).default(username),
            // Use the port to distinguish between multiple tunnels (webpack, metro).
            this.port,
            NGROK_CONFIG.domain, 
        ].join(".");
    }
    /** Start ngrok on the given port for the project. */ async startAsync({ timeout  } = {}) {
        // Ensure the instance is loaded first, this can linger so we should run it before the timeout.
        await this.resolver.resolveAsync({
            // For now, prefer global install since the package has native code (harder to install) and doesn't change very often.
            prefersGlobalInstall: true
        });
        // Ensure ADB reverse is running.
        if (!await (0, _adbReverse).startAdbReverseAsync([
            this.port
        ])) {
            // TODO: Better error message.
            throw new _errors.CommandError("NGROK_ADB", `Cannot start tunnel URL because \`adb reverse\` failed for the connected Android device(s).`);
        }
        this.serverUrl = await this._connectToNgrokAsync({
            timeout
        });
        Log.debug("[ngrok] Tunnel URL:", this.serverUrl);
        Log.log("Tunnel ready.");
    }
    /** Stop the ngrok process if it's running. */ async stopAsync() {
        var ref;
        Log.debug("[ngrok] Stopping Tunnel");
        await ((ref = this.resolver.get()) == null ? void 0 : ref.kill == null ? void 0 : ref.kill());
        this.serverUrl = null;
    }
    /** Exposed for testing. */ async _connectToNgrokAsync(options = {}, attempts = 0) {
        // Attempt to stop any hanging processes, this increases the chances of a successful connection.
        await this.stopAsync();
        // Get the instance quietly or assert otherwise.
        const instance = await this.resolver.resolveAsync({
            shouldPrompt: false,
            autoInstall: false
        });
        var _timeout;
        // TODO(Bacon): Consider dropping the timeout functionality:
        // https://github.com/expo/expo/pull/16556#discussion_r822307373
        const results = await (0, _delay).resolveWithTimeout(()=>this.connectToNgrokInternalAsync(instance, attempts)
        , {
            timeout: (_timeout = options.timeout) != null ? _timeout : TUNNEL_TIMEOUT,
            errorMessage: "ngrok tunnel took too long to connect."
        });
        if (typeof results === "string") {
            return results;
        }
        // Wait 100ms and then try again
        await (0, _delay).delayAsync(100);
        return this._connectToNgrokAsync(options, attempts + 1);
    }
    async connectToNgrokInternalAsync(instance, attempts = 0) {
        try {
            // Global config path.
            const configPath = path.join(_userSettings.default.getDirectory(), "ngrok.yml");
            Log.debug("[ngrok] Global config path:", configPath);
            const hostname = await this._getProjectHostnameAsync();
            Log.debug("[ngrok] Hostname:", hostname);
            const url = await instance.connect({
                authtoken: NGROK_CONFIG.authToken,
                proto: "http",
                hostname,
                configPath,
                onStatusChange (status) {
                    if (status === "closed") {
                        Log.error("We noticed your tunnel is having issues. " + "This may be due to intermittent problems with ngrok. " + "If you have trouble connecting to your app, try to restart the project, " + "or switch the host to `lan`.");
                    } else if (status === "connected") {
                        Log.log("Tunnel connected.");
                    }
                },
                port: this.port
            });
            return url;
        } catch (error) {
            // Attempt to connect 3 times
            if (attempts >= 2) {
                throw new _errors.CommandError("NGROK_CONNECT", error.toString());
            }
            // Attempt to fix the issue
            if ((error == null ? void 0 : error.error_code) === 103) {
                // Change randomness to avoid conflict if killing ngrok doesn't help
                await this._resetProjectRandomnessAsync();
            }
            return false;
        }
    }
    async getProjectRandomnessAsync() {
        const { urlRandomness: randomness  } = await _settings.ProjectSettings.readAsync(this.projectRoot);
        if (randomness) {
            return randomness;
        }
        return await this._resetProjectRandomnessAsync();
    }
    async _resetProjectRandomnessAsync() {
        const randomness = _crypto.default.randomBytes(5).toString("base64url");
        await _settings.ProjectSettings.setAsync(this.projectRoot, {
            urlRandomness: randomness
        });
        Log.debug("[ngrok] Resetting project randomness:", randomness);
        return randomness;
    }
}
exports.AsyncNgrok = AsyncNgrok;

//# sourceMappingURL=AsyncNgrok.js.map

Выполнить команду


Для локальной разработки. Не используйте в интернете!