docs: Add detail to Deno KV auth example (#1665)

This commit is contained in:
Josh Gum
2023-09-03 21:54:12 +00:00
committed by GitHub
parent f9ab05f7ea
commit 3858f5ad03
10 changed files with 22 additions and 16 deletions
+2 -1
View File
@@ -140,7 +140,8 @@ export default function MyIsland({ children, foo }: Props) {
<div>
<p>String from props: {foo}</p>
<p>
<button onClick={() => (number.value = randomNumber())}>Random</button>{" "}
<button onClick={() => (number.value = randomNumber())}>Random</button>
{" "}
number is: {number}.
</p>
</div>
+1 -1
View File
@@ -26,7 +26,7 @@ interface State {
export async function handler(
req: Request,
ctx: MiddlewareHandlerContext<State>
ctx: MiddlewareHandlerContext<State>,
) {
ctx.state.data = "myData";
const resp = await ctx.next();
+4 -4
View File
@@ -27,11 +27,11 @@ export async function handler(req: Request, ctx: MiddlewareHandlerContext) {
headers.set("Access-Control-Allow-Credentials", "true");
headers.set(
"Access-Control-Allow-Headers",
"Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With"
"Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With",
);
headers.set(
"Access-Control-Allow-Methods",
"POST, OPTIONS, GET, PUT, DELETE"
"POST, OPTIONS, GET, PUT, DELETE",
);
return resp;
@@ -66,11 +66,11 @@ export async function handler(_req: Request, ctx: MiddlewareHandlerContext) {
headers.set("Access-Control-Allow-Credentials", "true");
headers.set(
"Access-Control-Allow-Headers",
"Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With"
"Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With",
);
headers.set(
"Access-Control-Allow-Methods",
"POST, OPTIONS, GET, PUT, DELETE"
"POST, OPTIONS, GET, PUT, DELETE",
);
return resp;
+1 -1
View File
@@ -66,7 +66,7 @@ export class Context {
export async function handler(
req: Request,
ctx: MiddlewareHandlerContext<State>
ctx: MiddlewareHandlerContext<State>,
) {
ctx.state.context = Context.instance();
const resp = await ctx.next();
+1 -1
View File
@@ -30,7 +30,7 @@ export const handler: Handlers<Page> = {
let rawMarkdown = "";
if (ctx.params.slug === "remote") {
const resp = await fetch(
`https://raw.githubusercontent.com/denoland/fresh/main/docs/latest/introduction/index.md`
`https://raw.githubusercontent.com/denoland/fresh/main/docs/latest/introduction/index.md`,
);
if (resp.status !== 200) {
return ctx.render(undefined);
+2 -2
View File
@@ -270,8 +270,8 @@ export default function Home(req: Request, ctx: RouteContext) {
<>
<h1>
This page violates our configured CSP. But we don't have a{" "}
<code>RouteConfig</code> enabled, so Fresh doesn't know to use the CSP.
Styles will be applied.
<code>RouteConfig</code>{" "}
enabled, so Fresh doesn't know to use the CSP. Styles will be applied.
</h1>
<link rel="stylesheet" type="text/css" href="example.css" />
</>
+8 -1
View File
@@ -122,7 +122,14 @@ available.
}
```
5. Start your project with the necessary environment variables.
5. ⚠️ While Deno KV is still **experimental** you need to add the `--unstable`
option to the `start` task in the `deno.json` file.
```json
"start": "deno run -A --watch=static/,routes/ --unstable dev.ts",
```
6. Start your project with the necessary environment variables.
```sh
GITHUB_CLIENT_ID=xxx GITHUB_CLIENT_SECRET=xxx deno task start
@@ -53,7 +53,7 @@ export default function Countdown(props: { target: string }) {
}, [props.target]);
const secondsLeft = Math.floor(
(target.getTime() - now.value.getTime()) / 1000
(target.getTime() - now.value.getTime()) / 1000,
);
// If the target date has passed, we stop counting down.
+1 -1
View File
@@ -28,7 +28,7 @@ interface GitHubResponse {
export default async function Page(_req: Request, ctx: RouteContext) {
const resp = await fetch(
`https://api.github.com/users/${ctx.params.username}`
`https://api.github.com/users/${ctx.params.username}`,
);
if (!resp.ok) {
@@ -57,9 +57,7 @@ export default function Page({ data }: PageProps<Data>) {
<button type="submit">Search</button>
</form>
<ul>
{results.map((name) => (
<li key={name}>{name}</li>
))}
{results.map((name) => <li key={name}>{name}</li>)}
</ul>
</div>
);