= HashMap::new();
+ Template::render("404", &context)
+}
- let options: Options = serde_json::from_value(json!({
+fn rocket() -> Rocket {
+ let options: Options = serde_json::from_value(serde_json::json!({
"read_only": true,
"no_lock": true,
}))
.unwrap();
- let storage = Storage::new("db", options).unwrap();
+ let state = AppState {
+ storage: Storage::new("db", options).expect("open db")
+ };
- HttpServer::new(move || {
- let data = AppState {
- storage: storage.clone(),
- template: compile_templates!("./templates/**/*"),
- };
- App::new()
- .wrap(Logger::default())
- .data(data)
- .route("/q", web::to(index))
- .service(
- web::scope("/q")
- .service(actix_files::Files::new("/static", "./static"))
- .service(
- web::resource("/{id}")
- .name("question") // <- set resource name, then it could be used in `url_for`
- .guard(guard::Get())
- .to(show_question),
- )
- .service(
- web::resource("/{id}/a/")
- .name("answer") // <- set resource name, then it could be used in `url_for`
- .guard(guard::Get())
- .to(show_answer),
- )
- .route("/", web::to(index))
- )
- .route("/", web::to(index))
- })
- .bind("127.0.0.1:8088")
- .unwrap()
- .run()
- .unwrap();
+ let collection = state.storage.collection("questions").expect("collection \"questions\"");
+ collection.last_id().expect("\"questions\" last_id");
+
+ rocket::ignite()
+ .manage(state)
+ .register(catchers![not_found])
+ .mount("/", routes![index, show_question, show_answer])
+ .mount("/q", routes![index])
+ .mount("/q/static", StaticFiles::from("static/"))
+ .attach(Template::fairing())
+}
+
+fn main() {
+ rocket().launch();
}
diff --git a/templates/404.html b/templates/404.html.tera
similarity index 66%
rename from templates/404.html
rename to templates/404.html.tera
index 531d9e6..1fd0488 100644
--- a/templates/404.html
+++ b/templates/404.html.tera
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends "base" %}
{% block title %}404{% endblock title %}
{% block content %}
404 - Could not find that page
diff --git a/templates/answer.html b/templates/answer.html.tera
similarity index 92%
rename from templates/answer.html
rename to templates/answer.html.tera
index bd47828..db0bb4e 100644
--- a/templates/answer.html
+++ b/templates/answer.html.tera
@@ -1,4 +1,4 @@
-{% extends "base.html" %} {% block title %} Ответ {% endblock title %}
+{% extends "base" %} {% block title %} Ответ {% endblock title %}
{% block content %}
diff --git a/templates/base.html b/templates/base.html.tera
similarity index 91%
rename from templates/base.html
rename to templates/base.html.tera
index 758b3b8..79fc5ec 100644
--- a/templates/base.html
+++ b/templates/base.html.tera
@@ -7,7 +7,7 @@
{% block title %}{% endblock title %}
- {% include "nav.html" %}
+ {% include "nav" %}
{% block content %}{% endblock content %}