App-proxyforurl

 view release on metacpan or  search on metacpan

script/proxyforurl  view on Meta::CPAN

    sub ($err, @) {
      $c->render(text => exception_to_text($err), status => 500);
    }
  );
};

get '/v1/template' => {template => 'template'};

helper host_to_ip_p => sub ($c, $host) {
  return Mojo::IOLoop->subprocess->run_p(sub (@) {
    local $SIG{ALRM} = sub { die 'Timeout!' };
    alarm 2;
    my ($err, @info) = getaddrinfo $host;
    return undef if $err;

    @info = grep { $_->{family} & (AF_INET6 | AF_INET) } @info;
    for my $item (@info) {
      $item->{pri} = $item->{family} == AF_INET6 ? 0 : 1;
      @$item{qw(port ip)}
        = $item->{family} == AF_INET6
        ? unpack_sockaddr_in6($item->{addr})
        : unpack_sockaddr_in($item->{addr});
      $item->{ip} = inet_ntop @$item{qw(family ip)};
    }

    # IPv4 before IPv6
    @info = sort { $b->{pri} <=> $a->{pri} } @info;

    return @info && $info[0]{ip} || undef;
  })->catch(
    sub ($err, @) {
      return $err =~ m!Timeout! ? undef : Mojo::Promise->reject($err);
    }
  );
};

if (my $env_base = $ENV{PROXYFORURL_X_REQUEST_BASE}) {
  $env_base = '' unless $env_base =~ m!^http!;
  hook before_dispatch => sub ($c) {
    return unless my $base = $env_base || $c->req->headers->header('X-Request-Base');
    $c->req->url->base(Mojo::URL->new($base));
  };

script/proxyforurl  view on Meta::CPAN

  async timeRange() {
    return true;
  }

  async weekdayRange() {
    return true;
  }

  _animate(start) {
    const method = start ? 'setAttribute' : 'removeAttribute';
    setTimeout(() => {
      this.form.querySelector('button')[method]('aria-busy', true);
    }, (start ? 1 : 350));
  }

  async _init() {
    const res = await fetch(this.basePath + '/v1/template');
    const text = await res.text();

    if (!this.rulesInput.value) this.rulesInput.value = text;
    const yourIp = text.match(/Your IP: (\S+)/) || [];



( run in 0.226 second using v1.01-cache-2.11-cpan-4d50c553e7e )