2018-05-24 10:13:55 -07:00
|
|
|
// <ext>
|
2020-09-12 16:21:54 +01:00
|
|
|
use actix_web::{get, App, HttpRequest, HttpServer, Responder};
|
2018-05-24 10:13:55 -07:00
|
|
|
|
2020-09-12 16:21:54 +01:00
|
|
|
#[get("/")]
|
2019-12-29 04:10:02 +09:00
|
|
|
async fn index(req: HttpRequest) -> impl Responder {
|
2023-03-13 17:59:23 +00:00
|
|
|
let url = req.url_for("youtube", ["oHg5SJYRHA0"]).unwrap();
|
2018-05-24 10:13:55 -07:00
|
|
|
assert_eq!(url.as_str(), "https://youtube.com/watch/oHg5SJYRHA0");
|
2019-06-17 04:12:11 -04:00
|
|
|
|
2022-02-26 03:56:24 +00:00
|
|
|
url.to_string()
|
2018-05-24 10:13:55 -07:00
|
|
|
}
|
|
|
|
|
2020-09-12 16:21:54 +01:00
|
|
|
#[actix_web::main]
|
2019-12-29 04:10:02 +09:00
|
|
|
async fn main() -> std::io::Result<()> {
|
2019-06-25 18:20:36 -04:00
|
|
|
HttpServer::new(|| {
|
|
|
|
App::new()
|
2020-09-12 16:21:54 +01:00
|
|
|
.service(index)
|
2019-06-25 18:20:36 -04:00
|
|
|
.external_resource("youtube", "https://youtube.com/watch/{video_id}")
|
|
|
|
})
|
2022-02-26 03:56:24 +00:00
|
|
|
.bind(("127.0.0.1", 8080))?
|
2019-06-25 18:20:36 -04:00
|
|
|
.run()
|
2019-12-29 04:10:02 +09:00
|
|
|
.await
|
2018-05-24 10:13:55 -07:00
|
|
|
}
|
|
|
|
// </ext>
|