Skip to content

Commit

Permalink
Fix default url bug (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
sansyrox authored Nov 17, 2021
1 parent f2848c0 commit 0f157c3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
7 changes: 4 additions & 3 deletions integration_tests/base_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def putreq_with_body(request):


@app.delete("/delete")
async def delete(request):
async def delete():
return "DELETE Request"

@app.delete("/delete_with_body")
Expand All @@ -68,7 +68,7 @@ async def deletereq_with_body(request):


@app.patch("/patch")
async def patch(request):
async def patch():
return "PATCH Request"

@app.patch("/patch_with_body")
Expand All @@ -90,8 +90,9 @@ def blocker():


if __name__ == "__main__":
ROBYN_URL = os.getenv("ROBYN_URL", '0.0.0.0')
app.add_header("server", "robyn")
current_file_path = pathlib.Path(__file__).parent.resolve()
os.path.join(current_file_path, "build")
app.add_directory(route="/test_dir",directory_path=os.path.join(current_file_path, "build/"), index_file="index.html")
app.start(port=5000, url='0.0.0.0')
app.start(port=5000, url=ROBYN_URL)
11 changes: 11 additions & 0 deletions integration_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@

@pytest.fixture
def session():
os.environ["ROBYN_URL"] = "127.0.0.1"
current_file_path = pathlib.Path(__file__).parent.resolve()
base_routes = os.path.join(current_file_path, "./base_routes.py")
process = subprocess.Popen(["python3", base_routes])
time.sleep(1)
yield
process.terminate()

@pytest.fixture
def global_session():
os.environ["ROBYN_URL"] = "0.0.0.0"
current_file_path = pathlib.Path(__file__).parent.resolve()
base_routes = os.path.join(current_file_path, "./base_routes.py")
process = subprocess.Popen(["python3", base_routes])
Expand Down
13 changes: 13 additions & 0 deletions integration_tests/test_base_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import requests


def test_local_index_request(session):
BASE_URL = "http://127.0.0.1:5000"
res = requests.get(f"{BASE_URL}")
assert(res.status_code == 200)

def test_global_index_request(global_session):
BASE_URL = "http://0.0.0.0:5000"
res = requests.get(f"{BASE_URL}")
assert(res.status_code == 200)

2 changes: 1 addition & 1 deletion robyn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def start(self, url="127.0.0.1", port=5000):
:param port [int]: [reperesents the port number at which the server is listening]
"""
socket = SocketHeld(f"0.0.0.0:{port}", port)
socket = SocketHeld(url, port)
workers = self.workers
if not self.dev:
for process_number in range(self.processes):
Expand Down
3 changes: 1 addition & 2 deletions src/shared_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ impl SocketHeld {
#[new]
pub fn new(address: String, port: i32) -> PyResult<SocketHeld> {
let socket = Socket::new(Domain::IPV4, Type::STREAM, Some(Protocol::TCP))?;
let address: SocketAddr = format!("{}:{}", address, port).parse()?;
println!("{}", address);
let address: SocketAddr = address.parse()?;
socket.set_reuse_address(true)?;
//socket.set_reuse_port(true)?;
socket.bind(&address.into())?;
socket.listen(1024)?;

Expand Down

0 comments on commit 0f157c3

Please sign in to comment.