Last active
September 9, 2017 00:10
-
-
Save dupski/ea089d3e4dbe0cfe2773e561f117b7c6 to your computer and use it in GitHub Desktop.
Koa & Typescript with middleware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as Koa from 'koa'; | |
import * as Router from 'koa-router'; | |
const app = new Koa(); | |
app.use(async (ctx, next) => { | |
// Log the request to the console | |
console.log('Url:', ctx.url); | |
// Pass the request to the next middleware function | |
await next(); | |
}); | |
const router = new Router(); | |
router.get('/*', async (ctx) => { | |
ctx.body = 'Hello World!'; | |
}); | |
app.use(router.routes()); | |
app.listen(3000); | |
console.log('Server running on port 3000'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment