You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
route("/api/run_simulation", method = POST) do
try
# Access the current request
req = Genie.Requests.request()
println("Received request: ", req) # Debugging: log request
# Read and log the raw body
raw_body = String(req.body)
println("Received raw body: ", raw_body)
if isempty(raw_body)
println("Empty request body received.")
return HTTP.Response(400, "Bad Request: Empty body")
end
# Parse JSON from body
input_json = JSON.parse(raw_body)
println("Parsed JSON: ", input_json)
# Respond with a success message
response = Dict(
"message" => "Simulation received successfully",
"received_data" => input_json
)
return HTTP.Response(200, JSON.json(response))
# Placeholder simulation logic
result = Dict(
"data" => [
Dict("x" => [1, 2, 3], "y" => [4, 5, 6], "type" => "scatter", "name" => "Simulation")
],
"layout" => Dict(
"title" => "Simulation Results",
"xaxis" => Dict("title" => "Time"),
"yaxis" => Dict("title" => "Value")
)
)
# Respond with simulation results
return HTTP.Response(200, JSON.json(result))
catch e
println("Error processing request: ", e)
return HTTP.Response(500, "Internal Server Error")
end
end
Handle OPTIONS preflight requests for CORS
route("/api/run_simulation", method = OPTIONS) do
return HTTP.Response(200, headers = Dict(
"Access-Control-Allow-Origin" => "*",
"Access-Control-Allow-Methods" => "GET, POST, OPTIONS",
"Access-Control-Allow-Headers" => "Content-Type, Origin, Accept"
))
end
Start the Genie server
Genie.up()
Error stacktrace
If any error is thrown, please copy from the REPL and paste it here
To reproduce
Steps to reproduce the behavior and/or Julia code executed.
Expected behavior
A clear and concise description of what you expected to happen.
Additional context
Please include the output of julia> versioninfo()
and pkg> st
Then I make a request by Curl : curl -X POST -H "Content-Type: application/json" -d '{"timestep": "1s", "duration": "1d", "start_date": "2021-01-01T00:00"}' http://localhost:8000/api/run_simulation
Bad Request: Empty body(base)
I have Bad request, we don't have json inside at all
curl -X POST -H "Content-Type: application/json" -d '{"timestep": "1s", "duration": "1d", "start_date": "2021-01-01T00:00"}' http://localhost:8000/api/run_simulation
Bad Request: Empty body(base)
Please answer these optional questions to help us understand, prioritise, and assign the issue
1/ Are you using Genie at work or for hobby/personal projects? For work
2/ Can you give us, in a few words, some details about the app you're building with Genie? For simulation the energy market
The text was updated successfully, but these errors were encountered:
Describe the bug
A clear and concise description of what the bug is. I have code in Genie is like this
Import necessary packages
using Genie, Genie.Router, DataFrames, Arrow, Random, HTTP, JSON
Configure Genie
#Genie.config.run_as_server = true
Configure global CORS headers
Genie.config.cors_headers["Access-Control-Allow-Origin"] = "*" # Allow all origins
Genie.config.cors_headers["Access-Control-Allow-Methods"] = "GET, POST" # Allow methods
Genie.config.cors_headers["Access-Control-Allow-Headers"] = "Content-Type, Origin, Accept"
Define the simulation route
route("/api/run_simulation", method = POST) do
try
# Access the current request
req = Genie.Requests.request()
println("Received request: ", req) # Debugging: log request
end
Handle OPTIONS preflight requests for CORS
route("/api/run_simulation", method = OPTIONS) do
return HTTP.Response(200, headers = Dict(
"Access-Control-Allow-Origin" => "*",
"Access-Control-Allow-Methods" => "GET, POST, OPTIONS",
"Access-Control-Allow-Headers" => "Content-Type, Origin, Accept"
))
end
Start the Genie server
Genie.up()
Error stacktrace
If any error is thrown, please copy from the REPL and paste it here
To reproduce
Steps to reproduce the behavior and/or Julia code executed.
Expected behavior
A clear and concise description of what you expected to happen.
Additional context
Please include the output of
julia> versioninfo()
and
pkg> st
Then I make a request by Curl : curl -X POST -H "Content-Type: application/json" -d '{"timestep": "1s", "duration": "1d", "start_date": "2021-01-01T00:00"}' http://localhost:8000/api/run_simulation
Bad Request: Empty body(base)
I have Bad request, we don't have json inside at all
curl -X POST -H "Content-Type: application/json" -d '{"timestep": "1s", "duration": "1d", "start_date": "2021-01-01T00:00"}' http://localhost:8000/api/run_simulation
Bad Request: Empty body(base)
Please answer these optional questions to help us understand, prioritise, and assign the issue
1/ Are you using Genie at work or for hobby/personal projects? For work
2/ Can you give us, in a few words, some details about the app you're building with Genie? For simulation the energy market
The text was updated successfully, but these errors were encountered: