[meta] setup basic webserver

This commit is contained in:
wfrsk 2022-09-13 16:25:57 +02:00
parent 04287caedb
commit 7bf6a66473
No known key found for this signature in database
GPG Key ID: AA575FDE30E13CC6
5 changed files with 1540 additions and 6 deletions

1485
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -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"] }

26
rocket.yml Normal file
View File

@ -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

View File

@ -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 ]
)
}

View File

@ -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!" );
}
}