Skip to content

Commit dcf5598

Browse files
author
$
committed
for each versions
1 parent b753c04 commit dcf5598

23 files changed

+164
-0
lines changed
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = 'rust_web_app_2_undefined_path'
3+
version = "0.1.0"
4+
authors = ["$www.steadylearner.com"]
5+
edition = "2018"
6+
7+
[dependencies]
8+
rocket = "0.4.0"
9+
tera = "0.11.20"
10+
11+
[dependencies.rocket_contrib]
12+
version = "0.4.0"
13+
default-features = false
14+
features = ["tera_templates"]
15+
16+
# template and markdown
17+
tera = "0.11.20"
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#![feature(proc_macro_hygiene, decl_macro)]
2+
#[macro_use] extern crate rocket;
3+
4+
extern crate tera;
5+
6+
mod routes;
7+
use crate::routes::{ static_files, get, errors };
8+
9+
// tera
10+
use rocket_contrib::templates::Template;
11+
12+
fn rocket() -> rocket::Rocket {
13+
rocket::ignite()
14+
.attach(Template::fairing())
15+
.mount(
16+
"/",
17+
routes![
18+
static_files::file,
19+
get::index,
20+
],
21+
)
22+
.register(catchers![errors::not_found])
23+
}
24+
25+
fn main() {
26+
rocket().launch();
27+
}
28+
29+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use rocket::Request;
2+
use rocket_contrib::templates::Template;
3+
4+
#[catch(404)]
5+
pub fn not_found(req: &Request) -> Template {
6+
let mut map = std::collections::HashMap::new();
7+
map.insert("path", req.uri().path());
8+
Template::render("errors/not-found", &map)
9+
}
10+
11+
// https://api.rocket.rs/rocket_contrib/struct.Template.html
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use std::io;
2+
use rocket::response::{NamedFile};
3+
4+
#[get("/")]
5+
pub fn index() -> io::Result<NamedFile> {
6+
NamedFile::open("static/index.html")
7+
}
8+
9+
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod get;
2+
pub mod static_files;
3+
pub mod errors;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use std::path::{Path, PathBuf};
2+
use rocket::response::NamedFile;
3+
4+
#[get("/static/<file..>")]
5+
pub fn file(file: PathBuf) -> Option<NamedFile> {
6+
NamedFile::open(Path::new("static/").join(file)).ok()
7+
}

versions/#2 - undefined path/static/css/custom.css

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
body {
2+
margin: 0;
3+
}
4+
5+
.error {
6+
7+
/* layout */
8+
display: flex;
9+
flex-flow: column;
10+
justify-content: center;
11+
align-items: center;
12+
width: 100%;
13+
max-width: 100%;
14+
height: 100vh;
15+
16+
/* style */
17+
font-size: 1.2rem;
18+
box-shadow: inset 0 0 5px 5px black;
19+
}
20+
21+
22+
23+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!doctype html>
2+
<html lang=en>
3+
4+
<head>
5+
<meta charset=UTF-8>
6+
<meta name=viewport content="width=device-width,initial-scale=1">
7+
<meta http-equiv=X-UA-Compatible content="ie=edge">
8+
<meta name=author content=steadylearner>
9+
<title>Rust Rocket for beginner by steadylearner</title>
10+
<link rel="stylesheet" href="/static/main.css">
11+
</head>
12+
13+
<body>
14+
<div id=app></div>
15+
<h1 class="center-percent-absolute">This site will grow with Single Page App and Tera Template later</h1>
16+
<script type="text/javascript" src="/static/main.js"></script>
17+
</body>
18+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.center-percent-absolute {
2+
position: absolute;
3+
margin: 0;
4+
top: 50%;
5+
left: 50%;
6+
transform: translate(-50%, -50%);
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alert("Replace me with main.js from the React Single Page App later")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{% extends "main" %}
2+
3+
{% block title %} [404] Not Found {% endblock title %}
4+
5+
{% block css %}
6+
<link rel="stylesheet" href="/static/css/error.css">
7+
{% endblock css %}
8+
9+
{% block main %}
10+
<section class="error">
11+
<h1>No content for {{ path }} yet.</h1>
12+
<h2>
13+
<a href="/" alt="This is link to home [/] page.">
14+
Please, click this to back to the home page.
15+
</a>
16+
</h2>
17+
</section>
18+
{% endblock main %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{# [title, css, main] #}
2+
<!doctype html>
3+
<html lang=en>
4+
<head>
5+
<meta charset=UTF-8>
6+
<meta name=viewport content="width=device-width,initial-scale=1">
7+
<meta http-equiv=X-UA-Compatible content="ie=edge">
8+
<meta name=author content=steadylearner>
9+
<title>Rust Rocket for beginners by steadylearner</title>
10+
<link rel="stylesheet" href="/static/main.css">
11+
<title>{% block title %} Steadylearner Website {% endblock title %}</title>
12+
{% block css %}<link rel="stylesheet" href="/static/css/custom.css">{% endblock css %}
13+
</head>
14+
<body>
15+
<main role="main">
16+
{% block main %}{% endblock main %}
17+
</main>
18+
</body>
19+
</html>

0 commit comments

Comments
 (0)