forked from FoundKeyGang/FoundKey
WIP: Add additional handling of endpoints with v2 options
This commit is contained in:
parent
1e9e1e8b9c
commit
ca6156fe71
2 changed files with 23 additions and 0 deletions
|
@ -703,6 +703,24 @@ export interface IEndpointMeta {
|
|||
* 正常応答をキャッシュ (Cache-Control: public) する秒数
|
||||
*/
|
||||
readonly cacheSec?: number;
|
||||
|
||||
/**
|
||||
* API v2 options
|
||||
*/
|
||||
readonly v2?: {
|
||||
|
||||
/**
|
||||
* HTTP verb this endpoint supports
|
||||
*/
|
||||
readonly method: string;
|
||||
|
||||
/**
|
||||
* Path alias for v2 endpoint
|
||||
*
|
||||
* @example (v0) /api/notes/create -> /api/v2/notes
|
||||
*/
|
||||
readonly alias?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface IEndpoint {
|
||||
|
|
|
@ -74,6 +74,11 @@ for (const endpoint of endpoints) {
|
|||
} else {
|
||||
router.get(`/${endpoint.name}`, async ctx => { ctx.status = 405; });
|
||||
}
|
||||
|
||||
if (endpoint.meta.v2) {
|
||||
const path = endpoint.meta.v2.alias ?? endpoint.name.replace(/-/g, '_');
|
||||
router[endpoint.meta.v2.method](`/v2/${path}`, handler.bind(null, endpoint));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue