pub struct Web { /* private fields */ }Implementations§
source§impl Web
impl Web
sourcepub fn bind(ip: &str, public: &str, cors: JsonValue) -> Self
pub fn bind(ip: &str, public: &str, cors: JsonValue) -> Self
Examples found in repository?
examples/web.rs (line 33)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
fn main() {
let mut root_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
root_path = root_path.join("..");
let conf_web_path = root_path.join("config");
let conf_web_path = conf_web_path.join("web.json");
let conf_web_path = conf_web_path.to_str().unwrap();
let conf = match fs::read_to_string(conf_web_path) {
Ok(content) => {
if content == "" {
object! {}
} else {
json::parse(content.as_str()).unwrap()
}
}
Err(_) => {
object! {}
}
};
let public_path = root_path.join("df-web");
let public_path = public_path.join("examples");
let public_path = public_path.join("public");
let public_path = public_path.to_str().unwrap();
println!("http服务器启动 访问地址: {}", conf["url"].clone());
println!("公共目录: {}", public_path.clone());
Web::bind(conf["url"].as_str().unwrap(), public_path, conf["cors"].clone()).run(handle);
fn handle(response: JsonValue) -> (JsonValue, i32, String) {
println!("{:#}", response);
let text = object! {"name":"2313",response:response};
return (text, 200, "json".to_string());
}
}sourcepub fn run(&mut self, handle: fn(request: JsonValue) -> (JsonValue, i32, String))
pub fn run(&mut self, handle: fn(request: JsonValue) -> (JsonValue, i32, String))
运行
Examples found in repository?
examples/web.rs (line 33)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
fn main() {
let mut root_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
root_path = root_path.join("..");
let conf_web_path = root_path.join("config");
let conf_web_path = conf_web_path.join("web.json");
let conf_web_path = conf_web_path.to_str().unwrap();
let conf = match fs::read_to_string(conf_web_path) {
Ok(content) => {
if content == "" {
object! {}
} else {
json::parse(content.as_str()).unwrap()
}
}
Err(_) => {
object! {}
}
};
let public_path = root_path.join("df-web");
let public_path = public_path.join("examples");
let public_path = public_path.join("public");
let public_path = public_path.to_str().unwrap();
println!("http服务器启动 访问地址: {}", conf["url"].clone());
println!("公共目录: {}", public_path.clone());
Web::bind(conf["url"].as_str().unwrap(), public_path, conf["cors"].clone()).run(handle);
fn handle(response: JsonValue) -> (JsonValue, i32, String) {
println!("{:#}", response);
let text = object! {"name":"2313",response:response};
return (text, 200, "json".to_string());
}
}