This commit is contained in:
Ruidy 2021-03-04 22:02:31 +01:00
parent ff16b10fd7
commit 4cb341715c
3 changed files with 9 additions and 7 deletions

View file

@ -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

View file

@ -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
View file

@ -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>`;