mirror of https://github.com/embarklabs/embark.git
refactor(@embark/embark-utils): move checkIsAvailable to embark-utils
This commit is contained in:
parent
a46ea71dbd
commit
246715cd6b
|
@ -1,5 +1,19 @@
|
|||
const http = require('follow-redirects').http;
|
||||
const https = require('follow-redirects').https;
|
||||
|
||||
const {canonicalHost, defaultCorsHost, defaultHost, dockerHostSwap, isDocker} = require('./host');
|
||||
|
||||
function checkIsAvailable(url, callback) {
|
||||
const protocol = url.split(':')[0];
|
||||
const httpObj = (protocol === 'https') ? https : http;
|
||||
|
||||
httpObj.get(url, function (_res) {
|
||||
callback(true);
|
||||
}).on('error', function (_res) {
|
||||
callback(false);
|
||||
});
|
||||
}
|
||||
|
||||
const Utils = {
|
||||
joinPath: function() {
|
||||
const path = require('path');
|
||||
|
@ -9,7 +23,8 @@ const Utils = {
|
|||
defaultCorsHost,
|
||||
defaultHost,
|
||||
dockerHostSwap,
|
||||
isDocker
|
||||
isDocker,
|
||||
checkIsAvailable
|
||||
};
|
||||
|
||||
module.exports = Utils;
|
||||
|
|
|
@ -3,8 +3,7 @@ import {__} from "i18n";
|
|||
import {findNextPort} from "../../utils/network";
|
||||
import Server from "./server";
|
||||
|
||||
const utils = require("../../utils/utils.js");
|
||||
import {dockerHostSwap} from "embark-utils";
|
||||
import {dockerHostSwap, checkIsAvailable} from "embark-utils";
|
||||
|
||||
const DEFAULT_PORT = 55555;
|
||||
const DEFAULT_HOSTNAME = "localhost";
|
||||
|
@ -51,7 +50,7 @@ export default class Api {
|
|||
|
||||
private setServiceCheck() {
|
||||
this.embark.events.request("services:register", "api", (cb: (options: object) => any) => {
|
||||
utils.checkIsAvailable(this.apiUrl, (isAvailable: boolean) => {
|
||||
checkIsAvailable(this.apiUrl, (isAvailable: boolean) => {
|
||||
const devServer = __("Cockpit UI") + " (" + this.apiUrl + ")";
|
||||
const serverStatus = (isAvailable ? "on" : "off");
|
||||
return cb({name: devServer, status: serverStatus});
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import {findNextPort} from "../../utils/network";
|
||||
|
||||
var utils = require('../../utils/utils.js');
|
||||
import {joinPath, canonicalHost} from 'embark-utils';
|
||||
import {joinPath, canonicalHost, checkIsAvailable} from 'embark-utils';
|
||||
var Server = require('./server.js');
|
||||
const opn = require('opn');
|
||||
|
||||
|
@ -87,7 +86,7 @@ class WebServer {
|
|||
|
||||
this.events.request("services:register", 'Webserver', function (cb) {
|
||||
let url = self.protocol + '://' + canonicalHost(self.host) + ':' + self.port;
|
||||
utils.checkIsAvailable(url, function (available) {
|
||||
checkIsAvailable(url, function (available) {
|
||||
let devServer = __('Webserver') + ' (' + url + ')';
|
||||
let serverStatus = (available ? 'on' : 'off');
|
||||
return cb({name: devServer, status: serverStatus});
|
||||
|
|
|
@ -25,17 +25,6 @@ function recursiveMerge(target, source) {
|
|||
return merge.recursive(target, source);
|
||||
}
|
||||
|
||||
function checkIsAvailable(url, callback) {
|
||||
const protocol = url.split(':')[0];
|
||||
const httpObj = (protocol === 'https') ? https : http;
|
||||
|
||||
httpObj.get(url, function (_res) {
|
||||
callback(true);
|
||||
}).on('error', function (_res) {
|
||||
callback(false);
|
||||
});
|
||||
}
|
||||
|
||||
function httpGetRequest(httpObj, url, callback) {
|
||||
httpObj.get(url, function (res) {
|
||||
let body = '';
|
||||
|
@ -643,7 +632,6 @@ module.exports = {
|
|||
filesMatchingPattern,
|
||||
fileMatchesPattern,
|
||||
recursiveMerge,
|
||||
checkIsAvailable,
|
||||
httpGet,
|
||||
httpsGet,
|
||||
httpGetJson,
|
||||
|
|
Loading…
Reference in New Issue