fix: removed collage

fix: removing collage

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

chore: setup deno server package
This commit is contained in:
Daniel Ledda
2022-06-20 22:22:42 +02:00
parent 47301a822d
commit c628f6b46e
18 changed files with 288 additions and 130 deletions

25
server/main.ts Normal file
View File

@@ -0,0 +1,25 @@
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 }));
}
}