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:
25
server/main.ts
Normal file
25
server/main.ts
Normal 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 }));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user