hippofish/src/server/api/endpoints.ts

87 lines
2.1 KiB
TypeScript
Raw Normal View History

2018-07-15 20:43:36 +02:00
import * as path from 'path';
import * as glob from 'glob';
2018-07-15 20:25:35 +02:00
2018-07-15 20:43:36 +02:00
export interface IEndpointMeta {
2018-07-15 20:53:03 +02:00
desc?: any;
params?: any;
res?: any;
2018-07-15 20:25:35 +02:00
/**
*
* false
*/
requireCredential?: boolean;
/**
*
*
* withCredential false
*/
limit?: {
/**
*
*/
key?: string;
/**
* (ms)
* max
*/
duration?: number;
/**
* durationで指定した期間内にいくつまでリクエストできるのか
* duration
*/
max?: number;
/**
* (ms)
*/
minInterval?: number;
};
/**
*
* false
*/
withFile?: boolean;
/**
*
* false
*/
secure?: boolean;
/**
*
*
*/
kind?: string;
}
2018-07-15 20:43:36 +02:00
export interface IEndpoint {
name: string;
exec: any;
meta: IEndpointMeta;
}
const files = glob.sync('**/*.js', {
cwd: path.resolve(__dirname + '/endpoints/')
});
const endpoints: IEndpoint[] = files.map(f => {
const ep = require('./endpoints/' + f);
return {
name: f.replace('.js', ''),
exec: ep.default,
meta: ep.meta || {}
};
});
export default endpoints;