feat(server): Add basePath config to host from a directory (#2092)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
This commit is contained in:
co-authored by
Marvin Hagemeister
parent
fe792455ab
commit
9ab8651018
@@ -0,0 +1,11 @@
|
||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
||||
|
||||
export async function handler(
|
||||
_req: Request,
|
||||
ctx: MiddlewareHandlerContext<{ data: string }>,
|
||||
) {
|
||||
ctx.state.data = "it works";
|
||||
const resp = await ctx.next();
|
||||
resp.headers.set("server", "fresh server");
|
||||
return resp;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export default function B() {
|
||||
return <h1>it works</h1>;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export default function Relative() {
|
||||
return (
|
||||
<div>
|
||||
<a href="b">baz/foo</a>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
|
||||
export const handler: Handlers<unknown, { data: string }> = {
|
||||
GET(_req, ctx) {
|
||||
return new Response(ctx.basePath, {
|
||||
status: 200,
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
|
||||
export const handler: Handlers<unknown, { data: string }> = {
|
||||
GET(_req, ctx) {
|
||||
return new Response(ctx.state.data);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
|
||||
export const handler: Handlers<unknown, { data: string }> = {
|
||||
GET(req) {
|
||||
const url = new URL(req.url);
|
||||
return new Response(null, {
|
||||
status: 302,
|
||||
headers: {
|
||||
"Location": url.origin,
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
export default function Other() {
|
||||
return <h1>it works</h1>;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// deno-lint-ignore no-explicit-any
|
||||
export default function Page(): any {
|
||||
throw new Error("fail!!!");
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { Component } from "preact";
|
||||
|
||||
class ErrorBoundary extends Component {
|
||||
state = { error: null } as { error: Error | null };
|
||||
|
||||
static getDerivedStateFromError(error: Error) {
|
||||
return { error };
|
||||
}
|
||||
|
||||
render() {
|
||||
return this.state.error
|
||||
? <p>{this.state.error.message}</p>
|
||||
: <>{this.props.children}</>;
|
||||
}
|
||||
}
|
||||
|
||||
function Thrower(): preact.JSX.Element {
|
||||
throw new Error("it works");
|
||||
}
|
||||
|
||||
export default function ErrorBoundaryPage() {
|
||||
return (
|
||||
<ErrorBoundary>
|
||||
<Thrower />
|
||||
</ErrorBoundary>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { Head } from "$fresh/runtime.ts";
|
||||
|
||||
export default function Page() {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<link rel="stylesheet" href="/style.css" />
|
||||
</Head>
|
||||
<div>
|
||||
<div id="script-output" />
|
||||
<script src="/script.js"></script>
|
||||
<img class="img" src="/img.png" alt="" />
|
||||
<img
|
||||
class="img-srcset"
|
||||
src="/img.png"
|
||||
srcset="/img.png 480w, /img.png 800w"
|
||||
alt=""
|
||||
/>
|
||||
<picture>
|
||||
<source srcset="/img.png" media="(min-width: 600px)" />
|
||||
<img src="/img.png" alt="MDN" />
|
||||
</picture>
|
||||
<p class="foo">css style</p>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export default function Home() {
|
||||
return <h1>it works</h1>;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { useSignal } from "@preact/signals";
|
||||
import Counter from "../islands/Counter.tsx";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div>
|
||||
<Counter id="counter1" count={useSignal(3)} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user