Skip to content

Commit

Permalink
Fix http request header fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sansyrox committed Aug 29, 2021
1 parent 3702dce commit ca89857
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ impl Server {

HttpServer::new(move || {
let mut app = App::new();
let event_loop_hdl = event_loop_hdl.clone();
let directories = directories.read().unwrap();

// this loop matches three types of directory serving
// 1. Serves a build folder. e.g. the build folder generated from yarn build
// 2. Shows file listing
// 3. Just serves the file without any redirection to sub links
for directory in directories.iter() {
if let Some(index_file) = &directory.index_file {
app = app.service(
Expand All @@ -89,7 +95,6 @@ impl Server {
}
}

let event_loop_hdl = event_loop_hdl.clone();
app.app_data(web::Data::new(router.clone()))
.app_data(web::Data::new(headers.clone()))
.default_service(web::route().to(move |router, headers, payload, req| {
Expand Down
3 changes: 2 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async def test():

@app.post("/jsonify")
async def json(request):
print(request)
return jsonify({"hello": "world"})

@app.post("/post")
Expand Down Expand Up @@ -55,5 +56,5 @@ def blocker():

if __name__ == "__main__":
app.add_header("server", "robyn")
app.add_directory(route="/",directory_path="./test_dir/build", index_file="index.html")
app.add_directory(route="/test_dir",directory_path="./test_dir/build", index_file="index.html")
app.start(port=5000)

0 comments on commit ca89857

Please sign in to comment.