This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new local testing workflow (close snowplow#686)
- Loading branch information
Showing
5 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
cd core | ||
grunt | ||
cd .. | ||
grunt local | ||
if [[ "$(uname)" == "Darwin" ]]; then | ||
(sleep 1 && open http:127.0.0.1:8000/integration.html)& | ||
elif [[ "$(expr substr $(uname -s) 1 5)" == "Linux" ]]; then | ||
(sleep 1 && xdg-open http:127.0.0.1:8000/integration.html)& | ||
elif [[ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]]; then | ||
: | ||
elif [[ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]]; then | ||
: | ||
fi | ||
python3 ./tests/local/http-server.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import os | ||
import sys | ||
from http.server import HTTPServer, BaseHTTPRequestHandler | ||
from http.client import NO_CONTENT | ||
from pprint import pprint | ||
|
||
|
||
gif_string = b'GIF87a\x01\x00\x01\x00\x80\x00\x00\xff\xff\xff\xff\xff\xff,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;' | ||
file_path = os.path.dirname(__file__) | ||
|
||
def get_serve(file): | ||
return os.path.join(file_path, 'serve', file) | ||
|
||
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): | ||
|
||
def do_HEAD(self): | ||
self.send_response(200) | ||
if (self.path == '/integration.html'): | ||
self.send_header("Content-type", "text/html") | ||
self.end_headers() | ||
else: | ||
self.send_header("Content-type", "image/gif") | ||
self.end_headers() | ||
|
||
|
||
def do_GET(self): | ||
"""Respond to a GET request.""" | ||
self.send_response(200) | ||
if (self.path == '/integration.html'): | ||
self.send_header("Content-type", "text/html") | ||
self.end_headers() | ||
f = open(get_serve('integration.html'), "rb") | ||
body = f.read() | ||
f.close() | ||
self.wfile.write(body) | ||
elif (self.path == '/snowplow.js'): | ||
self.send_header("Content-type", "text/html") | ||
self.end_headers() | ||
f = open(get_serve('snowplow.js'), "rb") | ||
body = f.read() | ||
f.close() | ||
self.wfile.write(body) | ||
else: | ||
self.send_header("Content-type", "image/gif") | ||
self.end_headers() | ||
self.wfile.write(gif_string) | ||
|
||
def do_POST(self): | ||
self.send_response(200) | ||
self.send_header("Content-type", "image/gif") | ||
self.end_headers() | ||
self.wfile.write(''.encode()) | ||
#content_len = int(self.headers.get('content-length', 0)) | ||
#post_body = self.rfile.read(content_len) | ||
#pprint(post_body) | ||
|
||
def do_OPTIONS(self): | ||
self.send_response(200) | ||
self.send_header('Access-Control-Allow-Origin', 'null') | ||
self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS') | ||
self.send_header("Access-Control-Allow-Headers", "X-Requested-With") | ||
self.send_header("Access-Control-Allow-Headers", "Content-Type") | ||
self.end_headers() | ||
|
||
|
||
httpd = HTTPServer(('127.0.0.1', 8000), SimpleHTTPRequestHandler) | ||
try: | ||
httpd.serve_forever() | ||
except KeyboardInterrupt: | ||
print('User closed server with Ctrl-c') | ||
sys.exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters