Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.

Commit af3d878

Browse files
authored
Merge pull request #7 from technosophos/fix/use-path-info
fixed PATH_INFO problem
2 parents 3c542f4 + 594c0b0 commit af3d878

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# These are for both `run` (implicit) and `test` (explicit)
2-
PATH_INFO ?= /static/fileserver.gr
2+
PATH_INFO ?= /fileserver.gr
33
X_MATCHED_ROUTE ?= /static/...
44
BINDLE_SERVER_URL ?= http://localhost:8080/v1
55

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ SOFTWARE
138138

139139
The fileserver took `/static/filserver.gr`, removed the `/static/` part from the front, and then loaded `fileserver.gr` from the directory mounted in the `modules.toml`. Note that any subdirectories are also served. So `/static/foo/bar` would translate to the path `foo/bar` inside of the WebAssembly module (which in the example above would fully resolve to "/path/to/fileserver/foo/bar").
140140

141+
## Security Note
142+
143+
The Wagi fileserver is designed to serve any file mounted in the volume. Do not mount a
144+
volume that contains files you do not want served.
145+
141146
## Code of Conduct
142147

143148
This project has adopted the [Microsoft Open Source Code of

fileserver.gr

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import String from "string"
88
import Mediatype from "./lib/mediatype"
99
import Stringutil from "./lib/stringutil"
1010

11-
let serve = (path) => {
11+
let serve = (abs_path) => {
12+
// Trim the leading /
13+
let path = String.slice(1, String.length(abs_path), abs_path)
1214
File.fdWrite(File.stderr, "Fileserver: Loading file ")
1315
File.fdWrite(File.stderr, path)
1416
File.fdWrite(File.stderr, "\n")
@@ -45,14 +47,13 @@ let serve = (path) => {
4547
}
4648

4749
let guestpath = (env) => {
50+
51+
// Backward compat for an older version of Wagi that had PATH_INFO wrong.
52+
// X_RELATIVE_PATH was removed before Wagi 0.4
4853
match (Map.get("X_RELATIVE_PATH", env)) {
49-
Some(p) => p,
54+
Some(p) => String.concat("/", p),
5055
None => {
51-
// Backwards compat until Wagi 0.1.0 is released
52-
let req = Option.unwrap(Map.get("PATH_INFO", env))
53-
let matched = Option.unwrap(Map.get("X_MATCHED_ROUTE", env))
54-
let base = Stringutil.beforeLast("/...", matched)
55-
String.slice(String.length(base) + 1, String.length(req), req)
56+
Option.unwrap(Map.get("PATH_INFO", env))
5657
}
5758
}
5859

0 commit comments

Comments
 (0)