-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathhttp-server
executable file
·77 lines (70 loc) · 1.76 KB
/
http-server
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
#!/bin/bash
. /opt/cs50/lib/cli
# Default options
a="-a 0.0.0.0"
c="-c-1"
cors="--cors"
i="-i false"
port="-p 8080"
options="--no-dotfiles"
t="-t0"
# Check for app.py or wsgi.py
if [[ -f app.py ]] || [[ -f wsgi.py ]]; then
if ! _sure "Are you sure you want to run \`http-server\` and not \`flask\`?"; then
exit 1
fi
fi
# Check for path
if [[ $# -eq 1 ]] && [[ $1 != -* ]] && [[ ! $1 =~ ^\./?$ ]]; then
if ! _sure "Are you sure you want to serve \`${1}\` and not your current directory?"; then
exit 1
fi
fi
# Override default options
while test ${#} -gt 0
do
if [[ "$1" == "-a" ]]; then
a="$1 $2"
shift
shift
elif [[ "$1" =~ ^-a[0-9]+$ ]]; then
a="$1"
shift
elif [[ "$1" == "-c" ]]; then
c="$1 $2"
shift
shift
elif [[ "$1" =~ ^-c[+-]?[0-9]+$ ]]; then
c="$1"
shift
elif [[ "$1" =~ ^--cors(=.*)?$ ]]; then
cors="$1"
shift
elif [[ "$1" == "-i" ]]; then
i="$1"
shift
elif [[ "$1" == "-p" ]] || [[ "$1" == "--port" ]]; then
port="$1 $2"
shift
shift
elif [[ "$1" =~ ^-p[0-9]+$ ]]; then
port="$1"
shift
elif [[ "$1" == "-t" ]]; then
t="$1 $2"
shift
shift
elif [[ "$1" =~ ^-t[0-9]+$ ]]; then
t="$1"
shift
else
options+=" $1"
shift
fi
done
# Kill any process listing on the specified port
# using regex to handle -pxxxx, -p xxxx, --port xxxx, --port=xxxx
fuser --kill -TERM "${port//[^0-9]}/tcp" &>/dev/null
# Spawn http-server, suppressing
# (node:56) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
NODE_OPTIONS=--no-deprecation /usr/local/bin/http-server $a $c $cors $i $port $t $options