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] Select the locale by id
- [x] Use with CLI - [x] Use with CLI
- [x] Basic HTTP server - [x] Basic HTTP server
- [ ] HTML frontend - [x] HTML frontend
- [ ] Deployment - [ ] Deployment
## Installation ## Installation

View file

@ -9,13 +9,13 @@ const get_application = ({ port }: AppOpts): Application => {
const router = new Router(); const router = new Router();
router.get("/", (ctx: RouterContext) => { router.get("/", (ctx: RouterContext) => {
ctx.response.body = htmlBody(JSON.stringify(sayRandomHello(), null, 2)); ctx.response.body = htmlBody(sayRandomHello());
}).get("/:id", (ctx: RouterContext) => { }).get("/:id", (ctx: RouterContext) => {
try { try {
const value = ctx.params.id; const value = ctx.params.id;
if (!!value) { if (!!value) {
const id = new ID(parseInt(value, 10)); 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) { } catch (error) {
console.error(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> `<!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<style> <style>
body { body {
max-width: 650px; max-width: 650px;
margin: 40px auto; margin: 40px auto;
@ -38,7 +40,7 @@ export const htmlBody = (content: string) =>
<title>Hello client</title> <title>Hello client</title>
</head> </head>
<body> <body>
<h1>Hello client</h1> <h1>${hello}</h1>
<pre id="result">${content}</pre> <p>Language: ${language}</p>
</body> </body>
</html>`; </html>`;