MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

update examples

+22 -2
+4 -1
examples/npm/elysia/index.ts
··· 1 1 import { Elysia } from 'elysia'; 2 + import { logger } from './logger'; 3 + 4 + console.log('started on http://localhost:3000'); 2 5 3 - export default new Elysia().get('/', () => 'Hello Elysia!!'); 6 + export default new Elysia().use(logger()).get('/', () => 'hello elysia!!\n๐Ÿœ\n');
+17
examples/npm/elysia/logger.ts
··· 1 + import { Elysia } from 'elysia'; 2 + 3 + export const logger = ({ methods = ['GET', 'PUT', 'POST', 'DELETE'] } = {}) => 4 + new Elysia() 5 + .derive({ as: 'global' }, () => ({ start: Date.now() })) 6 + .onBeforeHandle({ as: 'global' }, ctx => { 7 + if (!methods.includes(ctx.request.method)) return; 8 + console.log('<--', ctx.request.method, ctx.path); 9 + }) 10 + .onAfterHandle({ as: 'global' }, ctx => { 11 + if (!methods.includes(ctx.request.method)) return; 12 + console.log('-->', ctx.request.method, ctx.path, ctx.set.status ?? Number.NaN, 'in', Date.now() - ctx.start, 'ms'); 13 + }) 14 + .onError({ as: 'global' }, ctx => { 15 + if (!methods.includes(ctx.request.method)) return; 16 + console.log('-->', ctx.request.method, ctx.path, ctx.set.status, 'in', ctx.start ? Date.now() - ctx.start : Number.NaN, 'ms'); 17 + });
+1 -1
examples/npm/hono/src/index.ts
··· 4 4 const app = new Hono(); 5 5 6 6 app.use(logger()); 7 - app.get('/', c => c.text('Hello ๐Ÿœ!')); 7 + app.get('/', c => c.text('hello hono!!\n๐Ÿœ\n')); 8 8 9 9 console.log('started on http://localhost:3000'); 10 10