mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 13:47:12 +00:00
Create httpserver
This commit is contained in:
parent
e5947cf650
commit
b8d7db9311
@ -145,9 +145,13 @@ jobs:
|
||||
- run:
|
||||
name: Start socket server
|
||||
command: ./scripts/socketserver/start.sh
|
||||
- run:
|
||||
name: Start http server
|
||||
command: ./scripts/httpserver/start.sh
|
||||
- run:
|
||||
name: Run tests
|
||||
environment:
|
||||
HTTPSERVER_ENABLED: 1
|
||||
TENDERMINT_ENABLED: 1
|
||||
SOCKETSERVER_ENABLED: 1
|
||||
SKIP_BUILD: 1
|
||||
@ -166,6 +170,7 @@ jobs:
|
||||
name: Run CLI examples
|
||||
working_directory: packages/cli
|
||||
environment:
|
||||
HTTPSERVER_ENABLED: 1
|
||||
TENDERMINT_ENABLED: 1
|
||||
SOCKETSERVER_ENABLED: 1
|
||||
SKIP_BUILD: 1
|
||||
@ -177,6 +182,7 @@ jobs:
|
||||
- run:
|
||||
name: Stop chains
|
||||
command: |
|
||||
./scripts/httpserver/stop.sh
|
||||
./scripts/socketserver/stop.sh
|
||||
./scripts/tendermint/all_stop.sh
|
||||
./scripts/<< parameters.simapp >>/stop.sh
|
||||
@ -265,8 +271,12 @@ jobs:
|
||||
- run:
|
||||
name: Start socket server
|
||||
command: ./scripts/socketserver/start.sh
|
||||
- run:
|
||||
name: Start http server
|
||||
command: ./scripts/httpserver/start.sh
|
||||
- run:
|
||||
environment:
|
||||
HTTPSERVER_ENABLED: 1
|
||||
SIMAPP42_ENABLED: 1
|
||||
SLOW_SIMAPP42_ENABLED: 1
|
||||
TENDERMINT_ENABLED: 1
|
||||
@ -285,6 +295,7 @@ jobs:
|
||||
name: Run CLI examples
|
||||
working_directory: packages/cli
|
||||
environment:
|
||||
HTTPSERVER_ENABLED: 1
|
||||
SIMAPP42_ENABLED: 1
|
||||
SLOW_SIMAPP42_ENABLED: 1
|
||||
TENDERMINT_ENABLED: 1
|
||||
@ -295,6 +306,7 @@ jobs:
|
||||
- run:
|
||||
name: Stop chains
|
||||
command: |
|
||||
./scripts/httpserver/stop.sh
|
||||
./scripts/socketserver/stop.sh
|
||||
./scripts/tendermint/all_stop.sh
|
||||
./scripts/simapp42/stop.sh
|
||||
@ -376,8 +388,12 @@ jobs:
|
||||
- run:
|
||||
name: Start socket server
|
||||
command: ./scripts/socketserver/start.sh
|
||||
- run:
|
||||
name: Start http server
|
||||
command: ./scripts/httpserver/start.sh
|
||||
- run:
|
||||
environment:
|
||||
HTTPSERVER_ENABLED: 1
|
||||
SIMAPP42_ENABLED: 1
|
||||
SLOW_SIMAPP42_ENABLED: 1
|
||||
TENDERMINT_ENABLED: 1
|
||||
@ -388,6 +404,7 @@ jobs:
|
||||
- run:
|
||||
name: Stop chains
|
||||
command: |
|
||||
./scripts/httpserver/stop.sh
|
||||
./scripts/socketserver/stop.sh
|
||||
./scripts/tendermint/all_stop.sh
|
||||
./scripts/simapp42/stop.sh
|
||||
@ -468,8 +485,12 @@ jobs:
|
||||
- run:
|
||||
name: Start socket server
|
||||
command: ./scripts/socketserver/start.sh
|
||||
- run:
|
||||
name: Start http server
|
||||
command: ./scripts/httpserver/start.sh
|
||||
- run:
|
||||
environment:
|
||||
HTTPSERVER_ENABLED: 1
|
||||
SIMAPP42_ENABLED: 1
|
||||
SLOW_SIMAPP42_ENABLED: 1
|
||||
TENDERMINT_ENABLED: 1
|
||||
@ -483,6 +504,7 @@ jobs:
|
||||
- run:
|
||||
name: Stop chains
|
||||
command: |
|
||||
./scripts/httpserver/stop.sh
|
||||
./scripts/socketserver/stop.sh
|
||||
./scripts/tendermint/all_stop.sh
|
||||
./scripts/simapp42/stop.sh
|
||||
|
@ -64,13 +64,19 @@ export TENDERMINT_ENABLED=1
|
||||
./scripts/socketserver/start.sh
|
||||
export SOCKETSERVER_ENABLED=1
|
||||
|
||||
# Start Http server
|
||||
./scripts/httpserver/start.sh
|
||||
export HTTPSERVER_ENABLED=1
|
||||
|
||||
# now more tests are running that were marked as "pending" before
|
||||
yarn test
|
||||
|
||||
# And at the end of the day
|
||||
unset HTTPSERVER_ENABLED
|
||||
unset SOCKETSERVER_ENABLED
|
||||
unset TENDERMINT_ENABLED
|
||||
unset LAUNCHPAD_ENABLED
|
||||
./scripts/httpserver/stop.sh
|
||||
./scripts/socketserver/stop.sh
|
||||
./scripts/tendermint/all_stop.sh
|
||||
./scripts/launchpad/stop.sh
|
||||
@ -100,6 +106,7 @@ order to avoid conflicts. Here is an overview of the ports used:
|
||||
| 1319 | wasmd LCD API | Manual Stargate debugging |
|
||||
| 4444 | socketserver | @cosmjs/sockets tests |
|
||||
| 4445 | socketserver slow | @cosmjs/sockets tests |
|
||||
| 5555 | httpserver | @cosmjs/tendermint-rpc tests |
|
||||
| 9090 | simapp gRPC | Manual Stargate debugging |
|
||||
| 11134 | Tendermint 0.34 RPC | @cosmjs/tendermint-rpc tests |
|
||||
| 26658 | simapp Tendermint RPC | Stargate client tests |
|
||||
|
7
scripts/httpserver/Dockerfile
Normal file
7
scripts/httpserver/Dockerfile
Normal file
@ -0,0 +1,7 @@
|
||||
FROM python:3.9-alpine
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY echo.py ./
|
||||
|
||||
ENTRYPOINT ["python", "./echo.py"]
|
53
scripts/httpserver/echo.py
Executable file
53
scripts/httpserver/echo.py
Executable file
@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
#pylint:disable=missing-docstring,invalid-name
|
||||
|
||||
import argparse
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
import json
|
||||
import sys
|
||||
|
||||
HOST = "0.0.0.0"
|
||||
|
||||
def log(data):
|
||||
print(data, flush=True)
|
||||
|
||||
class CORSRequestHandler(BaseHTTPRequestHandler):
|
||||
def end_headers(self):
|
||||
self.send_header("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
|
||||
self.send_header("Access-Control-Allow-Origin", "*")
|
||||
self.send_header("Access-Control-Allow-Headers", "*")
|
||||
BaseHTTPRequestHandler.end_headers(self)
|
||||
|
||||
def do_OPTIONS(self):
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
|
||||
def do_GET(self):
|
||||
"""Respond to a GET request."""
|
||||
if self.path == "/echo_headers":
|
||||
self.send_response(200)
|
||||
self.send_header("Content-type", "text/plain")
|
||||
self.send_header('Content-type', 'application/json')
|
||||
self.end_headers()
|
||||
body = {
|
||||
"request_headers": dict(self.headers)
|
||||
}
|
||||
self.wfile.write(json.dumps(body, sort_keys=True).encode())
|
||||
else:
|
||||
self.send_response(404)
|
||||
self.wfile.write("404. Try /echo_headers".encode())
|
||||
|
||||
def do_POST(self):
|
||||
self.do_GET()
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--port",
|
||||
help="Port to listen on",
|
||||
type=int,
|
||||
default=5555)
|
||||
args = parser.parse_args()
|
||||
httpd = HTTPServer((HOST, args.port), CORSRequestHandler)
|
||||
log("Starting server at {}:{}".format(HOST, args.port))
|
||||
httpd.serve_forever()
|
||||
log("Running now.")
|
31
scripts/httpserver/start.sh
Executable file
31
scripts/httpserver/start.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
set -o errexit -o nounset -o pipefail
|
||||
command -v shellcheck >/dev/null && shellcheck "$0"
|
||||
|
||||
# Please keep this in sync with the Ports overview in HACKING.md
|
||||
DEFAULT_PORT_GUEST="5555"
|
||||
DEFAULT_PORT_HOST="5555"
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
HTTPSERVER_DIR=$(mktemp -d "${TMPDIR:-/tmp}/httpserver.XXXXXXXXX")
|
||||
export HTTPSERVER_DIR
|
||||
echo "HTTPSERVER_DIR = $HTTPSERVER_DIR"
|
||||
|
||||
IMAGE_NAME="httpserver:local"
|
||||
CONTAINER_NAME="httpserver"
|
||||
|
||||
LOGFILE_DEFAULT="${HTTPSERVER_DIR}/httpserver_$DEFAULT_PORT_HOST.log"
|
||||
|
||||
docker build -t "$IMAGE_NAME" "$SCRIPT_DIR"
|
||||
|
||||
docker run --rm \
|
||||
--user="$UID" \
|
||||
--name "$CONTAINER_NAME" \
|
||||
-p "$DEFAULT_PORT_HOST:$DEFAULT_PORT_GUEST" \
|
||||
"$IMAGE_NAME" \
|
||||
>"$LOGFILE_DEFAULT" &
|
||||
|
||||
# Debug start
|
||||
sleep 3
|
||||
cat "$LOGFILE_DEFAULT"
|
8
scripts/httpserver/stop.sh
Executable file
8
scripts/httpserver/stop.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
set -o errexit -o nounset -o pipefail
|
||||
command -v shellcheck >/dev/null && shellcheck "$0"
|
||||
|
||||
CONTAINER_NAME="httpserver"
|
||||
|
||||
echo "Killing socketserver containers ..."
|
||||
docker container kill "$CONTAINER_NAME"
|
Loading…
x
Reference in New Issue
Block a user