summaryrefslogtreecommitdiff
path: root/tools/http_server.py
blob: fdb8686cd3db0149bc5a33ab7b6c642353d1e762 (plain)
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
#!/usr/bin/env python
# Many tests expect there to be an http server on port 4545 servering the deno
# root directory.
import os
from threading import Thread
import SimpleHTTPServer
import SocketServer
from util import root_path
from time import sleep

PORT = 4545


def server():
    os.chdir(root_path)  # Hopefully the main thread doesn't also chdir.
    Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
    SocketServer.TCPServer.allow_reuse_address = True
    s = SocketServer.TCPServer(("", PORT), Handler)
    print "Deno test server http://localhost:%d/" % PORT
    return s


def spawn():
    s = server()
    thread = Thread(target=s.serve_forever)
    thread.daemon = True
    thread.start()
    sleep(1)  # TODO I'm too lazy to figure out how to do this properly.
    return thread


if __name__ == '__main__':
    s = server()
    s.serve_forever()