2021-03-11 22:51:58 +01:00
|
|
|
import { BackstageController } from './backstage';
|
2021-04-16 15:29:23 +02:00
|
|
|
import ResetPasswordController from './auth/reset-password-controller';
|
2022-06-23 09:40:25 +02:00
|
|
|
import { SimplePasswordProvider } from './auth/simple-password-provider';
|
2022-09-16 09:54:27 +02:00
|
|
|
import { IUnleashConfig, IUnleashServices } from '../types';
|
2022-06-03 11:50:58 +02:00
|
|
|
import LogoutController from './logout';
|
2022-09-26 09:58:58 +02:00
|
|
|
import rateLimit from 'express-rate-limit';
|
2016-06-18 21:53:18 +02:00
|
|
|
|
2018-11-29 21:25:45 +01:00
|
|
|
const AdminApi = require('./admin-api');
|
2018-11-24 15:45:22 +01:00
|
|
|
const ClientApi = require('./client-api');
|
2018-12-03 08:59:13 +01:00
|
|
|
const Controller = require('./controller');
|
2022-06-20 12:22:41 +02:00
|
|
|
import { HealthCheckController } from './health-check';
|
2022-08-16 15:33:33 +02:00
|
|
|
import ProxyController from './proxy-api';
|
2022-11-21 11:57:07 +01:00
|
|
|
import { conditionalMiddleware } from '../middleware';
|
2022-09-01 15:26:26 +02:00
|
|
|
import EdgeController from './edge-api';
|
2022-09-30 13:01:32 +02:00
|
|
|
import { PublicInviteController } from './public-invite';
|
2023-02-16 08:08:51 +01:00
|
|
|
import { Db } from '../db/db';
|
2023-03-03 13:09:28 +01:00
|
|
|
import { minutesToMilliseconds } from 'date-fns';
|
2022-08-16 15:33:33 +02:00
|
|
|
|
2018-12-03 08:59:13 +01:00
|
|
|
class IndexRouter extends Controller {
|
2023-02-16 08:08:51 +01:00
|
|
|
constructor(config: IUnleashConfig, services: IUnleashServices, db: Db) {
|
2021-03-11 22:51:58 +01:00
|
|
|
super(config);
|
2022-08-26 15:16:29 +02:00
|
|
|
|
2021-04-22 10:07:10 +02:00
|
|
|
this.use('/health', new HealthCheckController(config, services).router);
|
2022-09-30 13:01:32 +02:00
|
|
|
this.use(
|
|
|
|
'/invite',
|
|
|
|
new PublicInviteController(config, services).router,
|
|
|
|
);
|
2021-02-16 14:30:08 +01:00
|
|
|
this.use('/internal-backstage', new BackstageController(config).router);
|
2022-09-23 14:19:17 +02:00
|
|
|
this.use('/logout', new LogoutController(config, services).router);
|
2022-09-26 09:58:58 +02:00
|
|
|
this.useWithMiddleware(
|
2021-04-09 13:46:53 +02:00
|
|
|
'/auth/simple',
|
|
|
|
new SimplePasswordProvider(config, services).router,
|
2022-09-26 09:58:58 +02:00
|
|
|
rateLimit({
|
2023-03-03 13:09:28 +01:00
|
|
|
windowMs: minutesToMilliseconds(1),
|
|
|
|
max: 10,
|
2022-09-26 09:58:58 +02:00
|
|
|
standardHeaders: true,
|
|
|
|
legacyHeaders: false,
|
|
|
|
}),
|
2021-04-09 13:46:53 +02:00
|
|
|
);
|
2021-04-16 15:29:23 +02:00
|
|
|
this.use(
|
|
|
|
'/auth/reset',
|
|
|
|
new ResetPasswordController(config, services).router,
|
|
|
|
);
|
2022-09-16 09:54:27 +02:00
|
|
|
|
2023-02-16 08:08:51 +01:00
|
|
|
this.use('/api/admin', new AdminApi(config, services, db).router);
|
2022-08-16 15:33:33 +02:00
|
|
|
this.use('/api/client', new ClientApi(config, services).router);
|
2017-06-28 10:20:22 +02:00
|
|
|
|
2022-08-26 15:16:29 +02:00
|
|
|
this.use(
|
|
|
|
'/api/frontend',
|
|
|
|
conditionalMiddleware(
|
|
|
|
() => config.flagResolver.isEnabled('embedProxy'),
|
2022-11-21 11:57:07 +01:00
|
|
|
new ProxyController(config, services, config.flagResolver)
|
|
|
|
.router,
|
2022-08-26 15:16:29 +02:00
|
|
|
),
|
|
|
|
);
|
2022-09-01 15:26:26 +02:00
|
|
|
|
|
|
|
this.use('/edge', new EdgeController(config, services).router);
|
2017-09-07 21:42:21 +02:00
|
|
|
}
|
2018-11-24 12:58:30 +01:00
|
|
|
}
|
2016-11-09 22:31:49 +01:00
|
|
|
|
2021-04-22 10:07:10 +02:00
|
|
|
export default IndexRouter;
|
|
|
|
|
2018-11-24 12:58:30 +01:00
|
|
|
module.exports = IndexRouter;
|