jdecool/scaleway-runtimepublic Fork
⑂ 41ffd77
Commits
⬇ Clone ▾
git clone https://git.rickub.com/jdecool/scaleway-runtime.git
git clone ssh://git@rickub.com/jdecool/scaleway-runtime.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP

test(example): serve Static Files end to endUnverified

Jérémy DECOOL committed 2026-11-22T11:45:23+01:00 Browse files
41ffd77 parent: c8fb53b
modified example/.gitignore +3 -0
@@ -4,3 +4,6 @@
44 /var/
55 /vendor/
66 /function.zip
7+# Precompressed Static File variants are shipped on purpose, whatever a global gitignore says.
8+!/public/**/*.gz
9+!/public/**/*.br
@@ -4,3 +4,6 @@
4 /var/4 /var/
5 /vendor/5 /vendor/
6 /function.zip6 /function.zip
7+# Precompressed Static File variants are shipped on purpose, whatever a global gitignore says.
8+!/public/**/*.gz
9+!/public/**/*.br
modified example/e2e/run.sh +32 -0
@@ -130,6 +130,38 @@ fi
130130 status=$(request missing "$base_url/missing")
131131 expect "unknown route" "$status" 404
132132
133+# Static Files, served by the runtime from public/ before the Application is built.
134+status=$(request css "$base_url/css/app.css")
135+expect "GET Static File status" "$status" 200
136+expect "Static File content type" "$(header css content-type)" text/css
137+expect "Static File body" "$(sha256 "$tmp/css.body")" "$(sha256 "$(dirname "$0")/../public/css/app.css")"
138+expect "Static File nosniff" "$(header css x-content-type-options)" nosniff
139+expect "Static File revalidated" "$(header css cache-control)" "public, max-age=0, must-revalidate"
140+etag=$(header css etag)
141+status=$(request css304 -H "If-None-Match: $etag" "$base_url/css/app.css")
142+expect "Static File with a matching If-None-Match" "$status" 304
143+status=$(request csshead -I "$base_url/css/app.css")
144+expect "HEAD Static File" "$status $(header csshead content-type)" "200 text/css"
145+
146+status=$(request gzip -H 'Accept-Encoding: gzip' "$base_url/css/app.css")
147+expect "precompressed variant encoding" "$(header gzip content-encoding)" gzip
148+expect "precompressed variant varies" "$(header gzip vary)" Accept-Encoding
149+expect "precompressed variant body" "$(php -r 'echo hash("sha256", (string) gzdecode(file_get_contents($argv[1])));' "$tmp/gzip.body")" "$(sha256 "$(dirname "$0")/../public/css/app.css")"
150+
151+status=$(request js "$base_url/js/greeting.js")
152+expect "JavaScript module content type" "$status $(header js content-type)" "200 text/javascript"
153+status=$(request png "$base_url/images/logo.png")
154+expect "image content type" "$status $(header png content-type)" "200 image/png"
155+expect "image body, base64 decoded by the platform" "$(sha256 "$tmp/png.body")" "$(sha256 "$(dirname "$0")/../public/images/logo.png")"
156+status=$(request digested "$base_url/assets/app-Ex4mPl3.css")
157+expect "digested Static File cached for good" "$(header digested cache-control)" "public, max-age=31536000, immutable"
158+
159+# Both reach the Application, which has no such route.
160+status=$(request frontcontroller "$base_url/index.php")
161+expect "the Front Controller is never served as a file" "$status" 404
162+status=$(request dotenv --path-as-is "$base_url/../.env")
163+expect "files outside public/ are not served" "$status" 404
164+
133165 status=$(request postroot -X POST -H 'Content-Type: application/json' --data '{"job":"cleanup"}' "$base_url/")
134166 expect "POST / JSON body" "$(field postroot args.job)" cleanup
135167
@@ -130,6 +130,38 @@ fi
130 status=$(request missing "$base_url/missing")130 status=$(request missing "$base_url/missing")
131 expect "unknown route" "$status" 404131 expect "unknown route" "$status" 404
132 132
133+# Static Files, served by the runtime from public/ before the Application is built.
134+status=$(request css "$base_url/css/app.css")
135+expect "GET Static File status" "$status" 200
136+expect "Static File content type" "$(header css content-type)" text/css
137+expect "Static File body" "$(sha256 "$tmp/css.body")" "$(sha256 "$(dirname "$0")/../public/css/app.css")"
138+expect "Static File nosniff" "$(header css x-content-type-options)" nosniff
139+expect "Static File revalidated" "$(header css cache-control)" "public, max-age=0, must-revalidate"
140+etag=$(header css etag)
141+status=$(request css304 -H "If-None-Match: $etag" "$base_url/css/app.css")
142+expect "Static File with a matching If-None-Match" "$status" 304
143+status=$(request csshead -I "$base_url/css/app.css")
144+expect "HEAD Static File" "$status $(header csshead content-type)" "200 text/css"
145+
146+status=$(request gzip -H 'Accept-Encoding: gzip' "$base_url/css/app.css")
147+expect "precompressed variant encoding" "$(header gzip content-encoding)" gzip
148+expect "precompressed variant varies" "$(header gzip vary)" Accept-Encoding
149+expect "precompressed variant body" "$(php -r 'echo hash("sha256", (string) gzdecode(file_get_contents($argv[1])));' "$tmp/gzip.body")" "$(sha256 "$(dirname "$0")/../public/css/app.css")"
150+
151+status=$(request js "$base_url/js/greeting.js")
152+expect "JavaScript module content type" "$status $(header js content-type)" "200 text/javascript"
153+status=$(request png "$base_url/images/logo.png")
154+expect "image content type" "$status $(header png content-type)" "200 image/png"
155+expect "image body, base64 decoded by the platform" "$(sha256 "$tmp/png.body")" "$(sha256 "$(dirname "$0")/../public/images/logo.png")"
156+status=$(request digested "$base_url/assets/app-Ex4mPl3.css")
157+expect "digested Static File cached for good" "$(header digested cache-control)" "public, max-age=31536000, immutable"
158+
159+# Both reach the Application, which has no such route.
160+status=$(request frontcontroller "$base_url/index.php")
161+expect "the Front Controller is never served as a file" "$status" 404
162+status=$(request dotenv --path-as-is "$base_url/../.env")
163+expect "files outside public/ are not served" "$status" 404
164+
133 status=$(request postroot -X POST -H 'Content-Type: application/json' --data '{"job":"cleanup"}' "$base_url/")165 status=$(request postroot -X POST -H 'Content-Type: application/json' --data '{"job":"cleanup"}' "$base_url/")
134 expect "POST / JSON body" "$(field postroot args.job)" cleanup166 expect "POST / JSON body" "$(field postroot args.job)" cleanup
135 167
added example/public/assets/app-Ex4mPl3.css +2 -0
new file mode 100644
@@ -0,0 +1,2 @@
1+/* The digested copy AssetMapper would write, listed in manifest.json: cached for good. */
2+body { background: Canvas; }
new file mode 100644
@@ -0,0 +1,2 @@
1+/* The digested copy AssetMapper would write, listed in manifest.json: cached for good. */
2+body { background: Canvas; }
added example/public/assets/manifest.json +3 -0
new file mode 100644
@@ -0,0 +1,3 @@
1+{
2+ "app.css": "/assets/app-Ex4mPl3.css"
3+}
new file mode 100644
@@ -0,0 +1,3 @@
1+{
2+ "app.css": "/assets/app-Ex4mPl3.css"
3+}
added example/public/css/app.css +15 -0
new file mode 100644
@@ -0,0 +1,15 @@
1+/* Served by the function as a Static File, without building the Application. */
2+:root {
3+ color-scheme: light dark;
4+ font-family: system-ui, sans-serif;
5+}
6+
7+body {
8+ margin: 2rem auto;
9+ max-width: 40rem;
10+ line-height: 1.5;
11+}
12+
13+code {
14+ font-family: ui-monospace, monospace;
15+}
new file mode 100644
@@ -0,0 +1,15 @@
1+/* Served by the function as a Static File, without building the Application. */
2+:root {
3+ color-scheme: light dark;
4+ font-family: system-ui, sans-serif;
5+}
6+
7+body {
8+ margin: 2rem auto;
9+ max-width: 40rem;
10+ line-height: 1.5;
11+}
12+
13+code {
14+ font-family: ui-monospace, monospace;
15+}
added example/public/css/app.css.gz +0 -0
new file mode 100644
Binary files /dev/null and b/example/public/css/app.css.gz differ
new file mode 100644
Binary files /dev/null and b/example/public/css/app.css.gz differBinary files /dev/null and b/example/public/css/app.css.gz differ
added example/public/images/logo.png +0 -0
new file mode 100644
Binary files /dev/null and b/example/public/images/logo.png differ
new file mode 100644
Binary files /dev/null and b/example/public/images/logo.png differBinary files /dev/null and b/example/public/images/logo.png differ
added example/public/js/greeting.js +1 -0
new file mode 100644
@@ -0,0 +1 @@
1+export const greeting = "Hello from a Static File";
new file mode 100644
@@ -0,0 +1 @@
1+export const greeting = "Hello from a Static File";