diff --git a/src/app.ts b/src/app.ts index 23d2b0fe..13b4e6f7 100644 --- a/src/app.ts +++ b/src/app.ts @@ -14,9 +14,11 @@ import namespaces from './namespaces'; export type AppState = DefaultState; -export type AppContext = RouterContext>; +}>; + +export type AppContext = RouterContext; export type AppMiddleware = Middleware; @@ -24,7 +26,7 @@ export type App = Koa export default ( articles: Articles, - router: Router, + router: Router, apiDocumentationPath: string, dataFactory: ExtendedDataFactory, ): App => { diff --git a/src/middleware/routing.ts b/src/middleware/routing.ts index 636b6230..6c95157c 100644 --- a/src/middleware/routing.ts +++ b/src/middleware/routing.ts @@ -1,22 +1,24 @@ -import Router, { RouterContext } from '@koa/router'; +import Router, { Middleware, RouterParamContext } from '@koa/router'; import createHttpError from 'http-errors'; -import { Middleware, Next, DefaultState } from 'koa'; +import { DefaultContextExtends, DefaultStateExtends, Next } from 'koa'; import compose from 'koa-compose'; -const notFound = (): Middleware => ( - async ({ _matchedRoute }: RouterContext, next: Next): Promise => { - await next(); +const notFound = + (): Middleware => ( + async ({ _matchedRoute }: RouterParamContext, next: Next): Promise => { + await next(); - if (typeof _matchedRoute === 'undefined') { - throw new createHttpError.NotFound(); + if (typeof _matchedRoute === 'undefined') { + throw new createHttpError.NotFound(); + } } - } -); + ); -export default (router: Router): Middleware => ( +export default +(router: Router): Middleware => ( compose([ router.routes(), - notFound(), + notFound(), router.allowedMethods({ throw: true }), ]) ); diff --git a/src/router.ts b/src/router.ts index 39a240c7..585ed62b 100644 --- a/src/router.ts +++ b/src/router.ts @@ -1,13 +1,13 @@ import Router from '@koa/router'; -import { AppContext, AppState } from './app'; +import { AppServiceContext, AppState } from './app'; import Routes from './routes'; import addArticle from './routes/add-article'; import apiDocumentation from './routes/api-documentation'; import articleList from './routes/article-list'; import entryPoint from './routes/entry-point'; -export default (): Router => { - const router = new Router(); +export default (): Router => { + const router = new Router(); router.get(Routes.ApiDocumentation, '/doc', apiDocumentation()); router.get(Routes.ArticleList, '/articles', articleList());