Update app.ts
Browse files
app.ts
CHANGED
|
@@ -1,8 +1,19 @@
|
|
| 1 |
-
import { Elysia } from "elysia";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
const app = new Elysia()
|
|
|
|
| 4 |
.get("/", () => "Hello, Elysia!")
|
| 5 |
.get("/items/:id", ({ params }) => `Item ID: ${params.id}`)
|
| 6 |
.listen(process.env.PORT);
|
| 7 |
|
| 8 |
-
console.log(`🦊 Elysia is running at http://localhost:
|
|
|
|
| 1 |
+
import { Elysia, t } from "elysia";
|
| 2 |
+
|
| 3 |
+
const loggerMiddleware = async ({ method, path, headers }, next) => {
|
| 4 |
+
console.log(`[${new Date().toISOString()}] ${method} ${path}`);
|
| 5 |
+
console.log(`Headers: ${JSON.stringify(headers)}`);
|
| 6 |
+
const start = Date.now();
|
| 7 |
+
const response = await next();
|
| 8 |
+
const duration = Date.now() - start;
|
| 9 |
+
console.log(`Response Time: ${duration}ms`);
|
| 10 |
+
return response;
|
| 11 |
+
};
|
| 12 |
|
| 13 |
const app = new Elysia()
|
| 14 |
+
.use(loggerMiddleware)
|
| 15 |
.get("/", () => "Hello, Elysia!")
|
| 16 |
.get("/items/:id", ({ params }) => `Item ID: ${params.id}`)
|
| 17 |
.listen(process.env.PORT);
|
| 18 |
|
| 19 |
+
console.log(`🦊 Elysia is running at http://localhost:7680`);
|