forked from metacpan/metacpan-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-dev
executable file
·68 lines (61 loc) · 2.01 KB
/
run-dev
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# This script is a convenient way to run metacpan-web from a local system
# without using Docker or any VM solution. It should be faster and more
# convenient to debug than running plackup manually.
#
# It starts two web servers. The first on port 5001 using a simple server
# with no concurrency (to aid in debugging) to handle the dynamic requests.
# The second on port 5000 using a "fast" server that can handle many
# concurrent requests which will serve the static files and proxy to the
# first server.
# Rather than running plackup, you can simply run:
#
# ./run-dev
#
# or
#
# carton exec ./run-dev
#
# Then browse to http://localhost:5000/
while [[ $# -gt 0 ]]; do
case "$1" in
--suffix)
METACPAN_WEB_CONFIG_LOCAL_SUFFIX="$2"
export METACPAN_WEB_CONFIG_LOCAL_SUFFIX
shift
;;
--suffix=*)
METACPAN_WEB_CONFIG_LOCAL_SUFFIX="${1:9}"
export METACPAN_WEB_CONFIG_LOCAL_SUFFIX
;;
*)
echo "Unsupported option $1" >&2
exit 1
;;
esac
shift
done
export METACPAN_WEB_PORT=5001
export COLUMNS="$(tput cols)"
[ -z "$PLACK_ENV" ] && PLACK_ENV=development
export PLACK_ENV
suffix="$METACPAN_WEB_CONFIG_LOCAL_SUFFIX"
[ -z "$suffix" ] && suffix="local"
log4perl="$(perl -MConfig::ZOMG -e'print Config::ZOMG->new(name => "MetaCPAN::Web")->load->{log4perl_file}')"
[ -z "$log4perl" ] && log4perl="log4perl.conf"
plackup -r -R metacpan_web.conf -R "metacpan_web_$suffix.conf" -R "$log4perl" -o localhost -p "$METACPAN_WEB_PORT" &
app_pid="$!"
trap 'kill "$app_pid"; exit 1' SIGHUP SIGINT SIGTERM SIGQUIT
while true; do
sleep 1
( echo '' >/dev/tcp/localhost/"$METACPAN_WEB_PORT" ) 2>/dev/null && break
done
for fast_handler in Gazelle Starlet Starman; do
perl -mPlack::Handler::$fast_handler -e1 &>/dev/null && break
done
unset HTTP_PROXY
unset http_proxy
unset HTTPS_PROXY
unset https_proxy
plackup --no-default-middleware -s "$fast_handler" -o localhost -p 5000 static-app.psgi
kill "$app_pid"