-
Notifications
You must be signed in to change notification settings - Fork 237
/
run-dev
executable file
·84 lines (76 loc) · 2.39 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/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 8000 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:8000/
METACPAN_PROXY_LISTEN="localhost:8000"
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
;;
-l)
METACPAN_PROXY_LISTEN="$2"
shift
;;
-l*)
METACPAN_PROXY_LISTEN="${1:2}"
;;
--listen)
METACPAN_PROXY_LISTEN="$2"
shift
;;
--listen=*)
METACPAN_PROXY_LISTEN="${1:9}"
;;
*)
echo "Unsupported option $1" >&2
exit 1
;;
esac
shift
done
export METACPAN_WEB_PORT=13272
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="$!"
npm run build:watch &
watch_pid="$!"
for sig in SIGHUP SIGINT SIGTERM SIGQUIT; do
trap "kill $app_pid $watch_pid; trap $sig; kill -s $sig $$; exit" "$sig"
done
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
plackup --no-default-middleware -s "$fast_handler" -l "$METACPAN_PROXY_LISTEN" static-app.psgi
kill "$app_pid"