mirror of https://github.com/wfrsk/violetta.git
[meta] setup basic webserver
This commit is contained in:
parent
04287caedb
commit
7bf6a66473
File diff suppressed because it is too large
Load Diff
|
@ -3,6 +3,10 @@ name = "violetta"
|
|||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[toolchain]
|
||||
channel = "nightly"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rocket = { version = "0.5.0-rc.2", features = ["secrets"] }
|
|
@ -0,0 +1,26 @@
|
|||
[default]
|
||||
address = "0.0.0.0"
|
||||
port =
|
||||
|
||||
[default.tls]
|
||||
certs = "path/to/cert-chain.pem"
|
||||
key = "path/to/key.pem"
|
||||
|
||||
[default.limits]
|
||||
form = "64 kB"
|
||||
json = "1 MiB"
|
||||
msgpack = "2 MiB"
|
||||
"file/jpg" = "5 MiB"
|
||||
|
||||
[default.shutdown]
|
||||
ctrlc = true
|
||||
signals = ["term", "hup"]
|
||||
grace = 5
|
||||
mercy = 5
|
||||
|
||||
[debug]
|
||||
port = 3000
|
||||
|
||||
limits = { json = "10MiB" }
|
||||
[release]
|
||||
port = 8443
|
24
src/main.rs
24
src/main.rs
|
@ -1,10 +1,24 @@
|
|||
mod test;
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn greet_user( user: &str ) -> String {
|
||||
format!( "Hello, {user}!" )
|
||||
use rocket::*;
|
||||
|
||||
#[get("/hello/<name>")]
|
||||
fn greet_user( name: String ) -> String {
|
||||
format!("Hello, {name}!")
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
#[get("/")]
|
||||
fn index( ) -> &'static str {
|
||||
"USAGE
|
||||
GET /hello/:name
|
||||
simply, greets you.
|
||||
"
|
||||
}
|
||||
|
||||
#[launch]
|
||||
pub fn rocket() -> _ {
|
||||
rocket::build()
|
||||
.mount(
|
||||
"/", routes![ index, greet_user ]
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use rocket::local::blocking::Client;
|
||||
use crate::*;
|
||||
|
||||
#[test]
|
||||
fn does_it_greet_us( ) {
|
||||
assert_eq!( greet_user( "John" ), "Hello, John!" );
|
||||
let client = Client::tracked( rocket() )
|
||||
.expect( "invalid rocket instance" );
|
||||
|
||||
let response = client.get( "/hello/World" ).dispatch( );
|
||||
assert_eq!( response.into_string( ).unwrap( ), "Hello, World!" );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue