Browse Source

gempress: add example

main
Garrit Franke 3 years ago
parent
commit
7c1fdf786c
Signed by: garrit
GPG Key ID: 65586C4DDA55EA2C
  1. 1
      .gitignore
  2. 24
      lib/gempress/examples/simple.rs
  3. 1
      lib/gempress/make_cert.sh

1
.gitignore vendored

@ -1 +1,2 @@
/target
*.pem

24
lib/gempress/examples/simple.rs

@ -0,0 +1,24 @@
mod gempress;
use gempress::{Gempress, Request, Response};
use std::path::Path;
pub fn handler(req: &Box<Request>, res: &mut Box<Response>) {
res.send("Hello World!\n");
}
fn main() {
// Run make_cert.sh to generate a certificate
let config = Gempress::Config {
certPath: Path::new("../cert.pem");
keyPath: Path::new("../key.pem");
}
let app = Gempress::new(config);
app.on("/", handler);
app.listen(1965, || {
println!("Listening on port 1965");
});
}

1
lib/gempress/make_cert.sh

@ -0,0 +1 @@
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj '/CN=localhost'
Loading…
Cancel
Save