fix: lint, scripts and updadte reeadme

This commit is contained in:
Ruidy 2021-05-18 09:23:06 +02:00
parent df159cc6cb
commit 75448f34b0
4 changed files with 15 additions and 8 deletions

2
.gitignore vendored
View file

@ -26,3 +26,5 @@ Icon
Network Trash Folder Network Trash Folder
Temporary Items Temporary Items
.apdisk .apdisk
.coverage

View file

@ -4,5 +4,8 @@ cli:
.PHONY: run .PHONY: run
run: run:
deno run --allow-net server.ts deno run --allow-net server.ts
.PHONY: lint
deno lint --unstable
tests: tests:
deno test --coverage --unstable deno test --coverage=.coverage --unstable
deno coverage .coverage

View file

@ -2,7 +2,7 @@
# Hello Server # Hello Server
Web app which returns the iconic Hello, World in various locales Web app which returns the iconic `Hello, World` in various locales.
## Features ## Features
@ -11,6 +11,7 @@ Web app which returns the iconic Hello, World in various locales
- [x] Use with CLI - [x] Use with CLI
- [x] Basic HTTP server - [x] Basic HTTP server
- [x] HTML frontend - [x] HTML frontend
- [ ] Rebuild using [Aleph.js](https://alephjs.org/docs)
- [ ] Deployment - [ ] Deployment
## Installation ## Installation

View file

@ -5,7 +5,7 @@ import { htmlBody } from "./view.ts";
const port = 8000; const port = 8000;
type AppOpts = { port: number }; type AppOpts = { port: number };
const get_application = ({ port }: AppOpts): Application => { const getApplication = ({ port }: AppOpts): Application => {
const router = new Router(); const router = new Router();
router.get("/", (ctx: RouterContext) => { router.get("/", (ctx: RouterContext) => {
@ -13,7 +13,7 @@ const get_application = ({ port }: AppOpts): Application => {
}).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(sayHello(id)); ctx.response.body = htmlBody(sayHello(id));
} }
@ -27,13 +27,14 @@ const get_application = ({ port }: AppOpts): Application => {
app.use(router.routes()); app.use(router.routes());
app.addEventListener("listen", ({ port }) => { app.addEventListener(
console.log(`Server listening on http://localhost:${port}/`); "listen",
}); () => console.log(`Server listening on http://localhost:${port}/`),
);
return app; return app;
}; };
const app = get_application({ port }); const app = getApplication({ port });
await app.listen({ port }); await app.listen({ port });
console.log(`Finished`); console.log(`Finished`);