Skip to content

Commit a4e73b6

Browse files
committed
Support for index.html on root
Signed-off-by: Mikkel Mørk Hegnhøj <[email protected]>
1 parent 3be1550 commit a4e73b6

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed
File renamed without changes.

index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<html>
2+
3+
<body>
4+
This is index in root
5+
</body>
6+
7+
</html>

spin.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ trigger = {type = "http", base = "/" }
99
[[component]]
1010
source = "target/wasm32-wasi/release/spin_static_fs.wasm"
1111
id = "fs"
12-
files = ["content/**/*"]
12+
files = [{ source = "", destination = "/" }]
1313
[component.trigger]
1414
route = "/..."
15+
[component.build]
16+
command = "make"

src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ fn serve(req: Request) -> Result<Response> {
7272
.map(|h| h.to_str())
7373
.unwrap_or(Ok(""))?;
7474

75+
let path = match path {
76+
"/" => "index.html",
77+
_ => path,
78+
};
79+
7580
let body = match FileServer::read(path, &enc) {
7681
Ok(b) => Some(b),
7782
Err(e) => {
@@ -267,4 +272,17 @@ mod tests {
267272
let rsp = <super::SpinHttp as spin_http::SpinHttp>::handle_http_request(req);
268273
assert_eq!(rsp.status, 404);
269274
}
275+
276+
#[test]
277+
fn test_serve_index() {
278+
let req = spin_http::Request {
279+
method: spin_http::Method::Get,
280+
uri: "http://thisistest.com".to_string(),
281+
headers: vec![(PATH_INFO_HEADER.to_string(), "/".to_string())],
282+
params: vec![],
283+
body: None,
284+
};
285+
let rsp = <super::SpinHttp as spin_http::SpinHttp>::handle_http_request(req);
286+
assert_eq!(rsp.status, 200);
287+
}
270288
}

0 commit comments

Comments
 (0)