-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from nyaomaru/deno-study-5
study: fetch data and docker
- Loading branch information
Showing
5 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# top-most EditorConfig file | ||
root = true | ||
|
||
# All files. | ||
[*] | ||
end_of_line = LF | ||
indent_style = space | ||
indent_size = 2 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.{md,mdx}] | ||
indent_size = 2 | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM denoland/deno:1.45.5 | ||
|
||
ARG GIT_REVISION | ||
ENV DENO_DEPLOYMENT_ID=${GIT_REVISION} | ||
|
||
WORKDIR /app | ||
|
||
COPY . . | ||
RUN deno cache main.ts | ||
|
||
EXPOSE 8000 | ||
|
||
CMD ["run", "-A", "main.ts"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Handlers, PageProps } from "$fresh/server.ts"; | ||
|
||
const projects = [{ id: 1, name: "Project 1", stars: 10 }, { | ||
id: 2, | ||
name: "Project 2", | ||
stars: 20, | ||
}]; | ||
|
||
interface Project { | ||
name: string; | ||
stars: number; | ||
message?: string; | ||
} | ||
|
||
export const handler: Handlers<Project> = { | ||
async GET(_req, ctx) { | ||
const project = await projects.find((project) => | ||
project.id === Number(ctx.params.id) | ||
); | ||
if (!project) { | ||
return ctx.renderNotFound({ | ||
name: "", | ||
stars: 0, | ||
message: "Project does not exist", | ||
}); | ||
} | ||
return ctx.render(project); | ||
}, | ||
}; | ||
|
||
export default function ProjectPage(props: PageProps<Project>) { | ||
if (props.data.message) { | ||
return <h1 class="text-4xl font-bold">{props.data.message}</h1>; | ||
} | ||
|
||
return ( | ||
<div> | ||
<h1 class="text-4xl font-bold">{props.data.name}</h1> | ||
<p>{props.data.stars} stars</p> | ||
</div> | ||
); | ||
} |