Skip to content

Commit

Permalink
Merge pull request #7 from technosophos/fix/use-path-info
Browse files Browse the repository at this point in the history
fixed PATH_INFO problem
  • Loading branch information
technosophos authored Aug 26, 2021
2 parents 3c542f4 + 594c0b0 commit af3d878
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# These are for both `run` (implicit) and `test` (explicit)
PATH_INFO ?= /static/fileserver.gr
PATH_INFO ?= /fileserver.gr
X_MATCHED_ROUTE ?= /static/...
BINDLE_SERVER_URL ?= http://localhost:8080/v1

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ SOFTWARE

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").

## Security Note

The Wagi fileserver is designed to serve any file mounted in the volume. Do not mount a
volume that contains files you do not want served.

## Code of Conduct

This project has adopted the [Microsoft Open Source Code of
Expand Down
15 changes: 8 additions & 7 deletions fileserver.gr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import String from "string"
import Mediatype from "./lib/mediatype"
import Stringutil from "./lib/stringutil"

let serve = (path) => {
let serve = (abs_path) => {
// Trim the leading /
let path = String.slice(1, String.length(abs_path), abs_path)
File.fdWrite(File.stderr, "Fileserver: Loading file ")
File.fdWrite(File.stderr, path)
File.fdWrite(File.stderr, "\n")
Expand Down Expand Up @@ -45,14 +47,13 @@ let serve = (path) => {
}

let guestpath = (env) => {

// Backward compat for an older version of Wagi that had PATH_INFO wrong.
// X_RELATIVE_PATH was removed before Wagi 0.4
match (Map.get("X_RELATIVE_PATH", env)) {
Some(p) => p,
Some(p) => String.concat("/", p),
None => {
// Backwards compat until Wagi 0.1.0 is released
let req = Option.unwrap(Map.get("PATH_INFO", env))
let matched = Option.unwrap(Map.get("X_MATCHED_ROUTE", env))
let base = Stringutil.beforeLast("/...", matched)
String.slice(String.length(base) + 1, String.length(req), req)
Option.unwrap(Map.get("PATH_INFO", env))
}
}

Expand Down

0 comments on commit af3d878

Please sign in to comment.