Skip to content

Commit 5891569

Browse files
authored
Merge pull request #75 from thefrontside/stdlib
✨Add stdlib to house common PlatformScript modules
2 parents 10a9bbe + 5b1d636 commit 5891569

5 files changed

Lines changed: 88 additions & 4 deletions

File tree

stdlib/examples/welcome.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Welcome to PlatformScript!

www/deno.lock

Lines changed: 55 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

www/fresh.gen.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import * as $5 from "./routes/gfm.css.ts";
1212
import * as $6 from "./routes/index.tsx";
1313
import * as $7 from "./routes/playground.tsx";
1414
import * as $8 from "./routes/pls.tsx";
15-
import * as $9 from "./routes/worker.js.ts";
15+
import * as $9 from "./routes/std.tsx";
16+
import * as $10 from "./routes/worker.js.ts";
1617
import * as $$0 from "./islands/CopyArea.tsx";
1718
import * as $$1 from "./islands/ps-playground.tsx";
1819

@@ -27,7 +28,8 @@ const manifest = {
2728
"./routes/index.tsx": $6,
2829
"./routes/playground.tsx": $7,
2930
"./routes/pls.tsx": $8,
30-
"./routes/worker.js.ts": $9,
31+
"./routes/std.tsx": $9,
32+
"./routes/worker.js.ts": $10,
3133
},
3234
islands: {
3335
"./islands/CopyArea.tsx": $$0,

www/routes/std.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Handlers, RouteConfig } from "$fresh/server.ts";
2+
import { serveFile } from "https://deno.land/std@0.176.0/http/file_server.ts";
3+
4+
export const handler: Handlers<unknown> = {
5+
async GET(req, cxt) {
6+
let { params: { path } } = cxt;
7+
let location = new URL(`../../stdlib/${path}`, import.meta.url);
8+
return await serveFile(req, location.pathname);
9+
},
10+
};
11+
12+
export const config: RouteConfig = { routeOverride: "/std{@:version}?/:path*" };

www/test/www.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,20 @@ describe("www", () => {
5959
`<base href="http://example.com/path/to/subdir/" />`,
6060
);
6161
});
62+
63+
it("can retrieve things from the standard library", async () => {
64+
let response = await fetch(
65+
"http://localhost:9999/std/examples/welcome.yaml",
66+
);
67+
let content = await response.text();
68+
expect(response.headers.get("Content-Type")).toContain("text/yaml");
69+
expect(content).toContain("Welcome to PlatformScript!");
70+
});
71+
72+
it("will not find things outside the 'libstd' directory`", async () => {
73+
let response = await fetch("http://localhost:9999/std/.../README.md");
74+
let text = await response.text();
75+
expect(response.status).toEqual(404);
76+
expect(text).toContain("Not Found");
77+
});
6278
});

0 commit comments

Comments
 (0)