UNPKG

ruud

Version:
43 lines (38 loc) 1.09 kB
import app from './src/index.js'; app({ port: 8888, socket: true, fallback: () => 'fallback route', after(ctx) { console.log('test route ' + ctx.middlewareProp + ' / ' + ctx.middlewarePropAfterRoute); }, routes: { '/': ctx => { ctx.middlewarePropFromRoute = 'prop from ROUTE'; return 'test route ' + ctx.middlewareProp + ' / ' + ctx.middlewarePropAfterRoute; }, hello: { '/': 'banana', goodbye: () => '...', you: { beast: () => 'beast', } } } }); app.use('/', async (ctx, next) => { ctx.middlewareProp = 'MW1'; await next(); console.log('mw1 var from route', ctx.middlewarePropFromRoute); ctx.middlewarePropAfterRoute = 'MW1 set AFTER route'; }) app.get('test', ctx => { return 'tester'; }) // Test different path formats app.get('simple', () => 'Simple path'); app.get('/with-slash', () => 'Path with slash'); app.get('nested/path', () => 'Nested path'); app.get('/nested/with-slash', () => 'Nested path with slash'); // Test all work correctly console.log('All routes:', Object.keys(app.allRoutes));