Templates: fix the content type of templates
Templating is weird af in Rocket. Look into 3a541ae
for more.
The content-type of the rendering is determined by the extension of the
template name.
But renaming these templates would break building the project for
development because it finds a phony template there. So the trick is to
default the `template_dir` to `args.upload` because it should never
interfere and will be always present.
This also fixes the hax in Dockerfile by making it the default.
Signed-off-by: Gunwant Jain <mail@wantguns.dev>
This commit is contained in:
parent
a11321c251
commit
edc247b558
|
@ -25,8 +25,6 @@ FROM scratch as runner
|
|||
COPY --from=builder /usr/local/cargo/bin/bin .
|
||||
|
||||
ENV BIN_ADDRESS=0.0.0.0
|
||||
# Some hax required since we are running on scratch
|
||||
ENV BIN_TEMPLATE_DIR=upload
|
||||
EXPOSE 6162
|
||||
|
||||
CMD ["./bin"]
|
||||
|
|
|
@ -6,7 +6,7 @@ services:
|
|||
ports:
|
||||
- 127.0.0.1:6163:6163
|
||||
environment:
|
||||
- BIN_PORT=6163
|
||||
- BIN_PORT=6163 # Defaults to 6162
|
||||
- BIN_LIMITS={form="16 MiB"}
|
||||
volumes:
|
||||
- ./upload:/upload # upload folder will have your pastes
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -22,10 +22,10 @@ fn setup_tera_engine(tera: &mut Tera) {
|
|||
|
||||
// and shove them in the tera instance
|
||||
tera.add_raw_templates(vec![
|
||||
("base", std::str::from_utf8(&base_html.data).unwrap()),
|
||||
("index", std::str::from_utf8(&index_html.data).unwrap()),
|
||||
("base.html", std::str::from_utf8(&base_html.data).unwrap()),
|
||||
("index.html", std::str::from_utf8(&index_html.data).unwrap()),
|
||||
(
|
||||
"pretty",
|
||||
"pretty.html",
|
||||
std::str::from_utf8(&pretty_html.data).unwrap(),
|
||||
),
|
||||
])
|
||||
|
@ -68,13 +68,13 @@ fn rocket() -> _ {
|
|||
// Custom Fairings and Providers
|
||||
let shield = Shield::default().disable::<NoSniff>();
|
||||
let figment = Figment::from(rocket::Config::default())
|
||||
.merge(("port", args.port))
|
||||
.merge(("address", args.address))
|
||||
.merge(("template_dir", ".")) // Required if embedding templates
|
||||
.merge(("port", &args.port))
|
||||
.merge(("address", &args.address))
|
||||
.merge(("template_dir", &args.upload)) // Required if embedding templates
|
||||
.merge(Env::prefixed("BIN_").global());
|
||||
|
||||
// create the upload directory, if not already created
|
||||
fs::create_dir_all(args.upload)
|
||||
fs::create_dir_all(&args.upload)
|
||||
.expect("Could not create the upload directory");
|
||||
|
||||
rocket::custom(figment)
|
||||
|
|
|
@ -6,5 +6,5 @@ use std::collections::HashMap;
|
|||
pub async fn index() -> Option<Template> {
|
||||
let mut map = HashMap::new();
|
||||
map.insert("title", "bin");
|
||||
Some(Template::render("index", &map))
|
||||
Some(Template::render("index.html", &map))
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ pub async fn pretty_retrieve(id: PasteId<'_>) -> Option<Template> {
|
|||
let mut map = HashMap::new();
|
||||
map.insert("title", id.to_string());
|
||||
map.insert("body", contents);
|
||||
let rendered = Template::render("pretty", &map);
|
||||
let rendered = Template::render("pretty.html", &map);
|
||||
|
||||
match tree_magic::match_filepath("text/plain", &filepath) {
|
||||
true => Some(rendered),
|
||||
|
|
|
@ -21,7 +21,7 @@ pub async fn pretty_retrieve_ext(
|
|||
let mut map = HashMap::new();
|
||||
map.insert("title", id.to_string());
|
||||
map.insert("body", contents);
|
||||
let rendered = Template::render("pretty", &map);
|
||||
let rendered = Template::render("pretty.html", &map);
|
||||
|
||||
match tree_magic::match_filepath("text/plain", &filepath) {
|
||||
true => Some(rendered),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends "base" %}
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block styles %}
|
||||
<link rel="stylesheet" href="/static/css/index.css">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends "base" %}
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block styles %}
|
||||
<style>
|
||||
|
|
Loading…
Reference in New Issue