Skip to content

Instantly share code, notes, and snippets.

@dupski
Last active September 9, 2017 00:10
Show Gist options
  • Save dupski/ea089d3e4dbe0cfe2773e561f117b7c6 to your computer and use it in GitHub Desktop.
Save dupski/ea089d3e4dbe0cfe2773e561f117b7c6 to your computer and use it in GitHub Desktop.
Koa & Typescript with middleware
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