Reputation: 23
I try to give the Client the HTML, CSS and JavaScript file but it doesn't work.
async fn get_homepage() -> impl Responder {
let html = include_str!("../../../../Frontend/Code/homepage.html");
HttpResponse::Ok().content_type("text/html").body(html)
}
This can only send the HTML and it works fine, but when I try:
async fn get_homepage() -> impl Responder {
let html = include_str!("Path of HTML-File");
HttpResponse::Ok().content_type("text/html").body(html);
HttpResponse::Ok()
.content_type("text/css")
.body("Path of CSS-File")
}
I only see the CSS.
How can I display the complete website?
Upvotes: 0
Views: 646
Reputation: 834
In Rust, the last statement without a semicolon will be treated as the return value so you'll see the first function to return the html file and the second function to return the css file because it is the last statement.
fn return_two() -> i32 {
1;
2
}
You need to serve the css and html file on 2 different urls.
#[get("/")]
async fn ...
#[get("/style.css")]
async fn ...
Alternatively, you can inline the css in the html file like this
<head>
<style> /* your style goes here */ </style>
</head>
Upvotes: 2