mirror of
https://github.com/rjNemo/deno_hello
synced 2026-06-06 01:56:40 +00:00
frontend
This commit is contained in:
parent
ff16b10fd7
commit
4cb341715c
3 changed files with 9 additions and 7 deletions
|
|
@ -10,7 +10,7 @@ Web app which returns the iconic Hello, World in various locales
|
|||
- [x] Select the locale by id
|
||||
- [x] Use with CLI
|
||||
- [x] Basic HTTP server
|
||||
- [ ] HTML frontend
|
||||
- [x] HTML frontend
|
||||
- [ ] Deployment
|
||||
|
||||
## Installation
|
||||
|
|
|
|||
|
|
@ -9,13 +9,13 @@ const get_application = ({ port }: AppOpts): Application => {
|
|||
const router = new Router();
|
||||
|
||||
router.get("/", (ctx: RouterContext) => {
|
||||
ctx.response.body = htmlBody(JSON.stringify(sayRandomHello(), null, 2));
|
||||
ctx.response.body = htmlBody(sayRandomHello());
|
||||
}).get("/:id", (ctx: RouterContext) => {
|
||||
try {
|
||||
const value = ctx.params.id;
|
||||
if (!!value) {
|
||||
const id = new ID(parseInt(value, 10));
|
||||
ctx.response.body = htmlBody(JSON.stringify(sayHello(id), null, 2));
|
||||
ctx.response.body = htmlBody(sayHello(id));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
|
|
|||
10
view.ts
10
view.ts
|
|
@ -1,8 +1,10 @@
|
|||
export const htmlBody = (content: string) =>
|
||||
import { Locale } from "./src/repositories/locales.ts";
|
||||
|
||||
export const htmlBody = ({ locale: language, message: hello }: Locale) =>
|
||||
`<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<style>
|
||||
<style>
|
||||
body {
|
||||
max-width: 650px;
|
||||
margin: 40px auto;
|
||||
|
|
@ -38,7 +40,7 @@ export const htmlBody = (content: string) =>
|
|||
<title>Hello client</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello client</h1>
|
||||
<pre id="result">${content}</pre>
|
||||
<h1>${hello}</h1>
|
||||
<p>Language: ${language}</p>
|
||||
</body>
|
||||
</html>`;
|
||||
|
|
|
|||
Loading…
Reference in a new issue