Skip to content

Commit

Permalink
feat: add Heroku proc file for starting the web server
Browse files Browse the repository at this point in the history
Also support for changing port where the server is running
  • Loading branch information
drodil committed Sep 3, 2021
1 parent 8758cb2 commit f717f4e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: ./target/release/rustybeer-server
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ To start the server:
cargo run --bin rustybeer-server
```

You can access the OpenAPI UI from http://localhost:3000/docs
You can access the OpenAPI UI from http://localhost:3000/docs. To change the
port number, you can define environment variable PORT.

## Testing

Expand Down
10 changes: 9 additions & 1 deletion rustybeer-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod handlers;

use rweb::*;
use std::env;

/// Renders the homepage. TODO: Change this to return HTML
/// and link to /docs
Expand All @@ -9,13 +10,20 @@ fn default() -> String {
return "Check the /docs".to_string();
}

fn get_port() -> u16 {
match env::var("PORT") {
Ok(val) => val.parse::<u16>().unwrap(),
_ => 3000,
}
}

#[tokio::main]
async fn main() {
let (spec, filter) = openapi::spec().build(move || {
handlers::abv::abv().or(handlers::abv::fg().or(handlers::beer_style::search()))
});

serve(filter.or(default()).or(openapi_docs(spec)))
.run(([0, 0, 0, 0], 3000))
.run(([0, 0, 0, 0], get_port()))
.await;
}

0 comments on commit f717f4e

Please sign in to comment.