Files
stocca-tre/server/main.ts
Daniel Ledda c628f6b46e fix: removed collage
fix: removing collage

feat: added ingredient type to server for testing and a config"

chore: setup deno server package
2022-06-21 23:07:01 +02:00

25 lines
759 B
TypeScript

import createNewDbConnection from "./database.ts";
import IngredientService from "./Ingredient.ts";
const server = Deno.listen({ port: 8080 });
console.log(`HTTP webserver running. Access it at: http://localhost:8080/`);
const database = await createNewDbConnection();
const ingredientService = new IngredientService(database);
for await (const conn of server) {
serveHttp(conn);
}
async function serveHttp(conn: Deno.Conn) {
const httpConn = Deno.serveHttp(conn);
for await (const requestEvent of httpConn) {
const body = [];
for (const ingredient of (await ingredientService.getAllIngredients())) {
body.push(ingredient);
}
requestEvent.respondWith(Response.json(body, { status: 200 }));
}
}