fix: removing collage feat: added ingredient type to server for testing and a config" chore: setup deno server package
25 lines
759 B
TypeScript
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 }));
|
|
}
|
|
} |