mirror of
https://github.com/ANL-CEEESA/UnitCommitment.jl.git
synced 2025-12-06 16:28:51 -06:00
web: backend: Allow user to choose HOST
This commit is contained in:
@@ -74,7 +74,7 @@ function jobs_view(req)
|
|||||||
return HTTP.Response(200, response_body)
|
return HTTP.Response(200, response_body)
|
||||||
end
|
end
|
||||||
|
|
||||||
function start_server(port::Int = 8080; optimizer)
|
function start_server(host, port; optimizer)
|
||||||
Random.seed!()
|
Random.seed!()
|
||||||
|
|
||||||
function work_fn(job_id)
|
function work_fn(job_id)
|
||||||
@@ -121,7 +121,7 @@ function start_server(port::Int = 8080; optimizer)
|
|||||||
# Register job/*/view endpoint
|
# Register job/*/view endpoint
|
||||||
HTTP.register!(router, "GET", "/jobs/*/view", jobs_view)
|
HTTP.register!(router, "GET", "/jobs/*/view", jobs_view)
|
||||||
|
|
||||||
server = HTTP.serve!(router, port; verbose = false)
|
server = HTTP.serve!(router, host, port; verbose = false)
|
||||||
return ServerHandle(server, processor)
|
return ServerHandle(server, processor)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -2,17 +2,18 @@
|
|||||||
# Copyright (C) 2025, UChicago Argonne, LLC. All rights reserved.
|
# Copyright (C) 2025, UChicago Argonne, LLC. All rights reserved.
|
||||||
# Released under the modified BSD license. See COPYING.md for more details.
|
# Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
|
||||||
|
const HOST = "127.0.0.1"
|
||||||
const PORT = 32617
|
const PORT = 32617
|
||||||
|
|
||||||
function server_test_usage()
|
function server_test_usage()
|
||||||
server = Backend.start_server(PORT; optimizer = HiGHS.Optimizer)
|
server = Backend.start_server(HOST, PORT; optimizer = HiGHS.Optimizer)
|
||||||
try
|
try
|
||||||
# Read the compressed fixture file
|
# Read the compressed fixture file
|
||||||
compressed_data = read(fixture("case14.json.gz"))
|
compressed_data = read(fixture("case14.json.gz"))
|
||||||
|
|
||||||
# Submit test case
|
# Submit test case
|
||||||
response = HTTP.post(
|
response = HTTP.post(
|
||||||
"http://localhost:$PORT/submit",
|
"http://$HOST:$PORT/submit",
|
||||||
["Content-Type" => "application/gzip"],
|
["Content-Type" => "application/gzip"],
|
||||||
compressed_data,
|
compressed_data,
|
||||||
)
|
)
|
||||||
@@ -42,7 +43,7 @@ function server_test_usage()
|
|||||||
@test saved_data == compressed_data
|
@test saved_data == compressed_data
|
||||||
|
|
||||||
# Query job information
|
# Query job information
|
||||||
view_response = HTTP.get("http://localhost:$PORT/jobs/$job_id/view")
|
view_response = HTTP.get("http://$HOST:$PORT/jobs/$job_id/view")
|
||||||
@test view_response.status == 200
|
@test view_response.status == 200
|
||||||
|
|
||||||
# Check response
|
# Check response
|
||||||
|
|||||||
Reference in New Issue
Block a user