-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstart-frontend
executable file
·46 lines (45 loc) · 2.47 KB
/
start-frontend
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
##############################################################################
# #
# Copyright 2013 TripAdvisor, LLC #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
# you may not use this file except in compliance with the License. #
# You may obtain a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# #
##############################################################################
# takes one optional arg, the path to an HQT config file
set -e
webroot="$(dirname "$0")"
source "$webroot/hqt-setup"
export MOJO_REVERSE_PROXY=1
exec perl - "$webroot" "$1" <<'END'
use strict;
use warnings;
use File::Basename qw( dirname );
use File::Spec::Functions qw( catfile );
use YAML::Any qw();
use Mojo::Server::Morbo;
my $webroot = shift;
my $cfg_file = shift || catfile $webroot, qw( conf hqt_config.yaml );
my $cfg_dir = dirname $cfg_file;
my $app_file = catfile $webroot, qw( script hive-query-tool.webapp.pl );
my $cfg = YAML::Any::LoadFile( $cfg_file ) or die "Couldn't load YAML from $cfg_file\n";
my $tmpl_dir = $cfg->{hql_template_dir};
my $listen = $cfg->{frontend_listen} || 'http://*:3000';
my @listen_a = ref $listen eq 'ARRAY' ? @$listen
: ! ref $listen ? ( $listen )
: die "Couldn't figure out where the HTTP server should listen!\n";
my $morbo = Mojo::Server::Morbo->new;
$morbo->watch( [ glob( "$webroot/lib,public,templates}" ), $cfg_dir, $tmpl_dir ] );
$ENV{MOJO_LISTEN} = join(',', @listen_a); # see src for morbo command, ugh.
$morbo->run( $app_file );
END