Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private loadRoutes() {
// TODO: Rename services to controllers, and controllers to services. They're backwards.
const apis = ["scalar", "dimension", "admin", "matrix"].map(a => path.join(__dirname, a, "*.js"));
const router = express.Router();
Server.useIoC();
Server.registerAuthenticator(new MatrixSecurity());
apis.forEach(a => Server.loadServices(router, [a]));
const routes = _.uniq(router.stack.map(r => r.route.path));
for (const route of routes) {
this.app.options(route, (_req, res) => res.sendStatus(200));
LogService.info("Webserver", "Registered route: " + route);
}
this.app.use(router);
// We register the default route last to make sure we don't override anything by accident.
// We'll pass off all other requests to the web app
this.app.get(/(widgets\/|riot\/|\/)*/, (_req, res) => {
res.sendFile(path.join(__dirname, "..", "..", "web", "index.html"));
});
// Set up the error handler
import { SchemaController } from './schema';
import { TagsController } from './tags';
import { SearchController } from './search';
import { AppsController } from './apps';
import { PolicyController } from './policies';
import { ResourcePolicyController } from './resource-policy';
import { SubjectExtractionRulesController } from './subject-extraction-rules';
import { RoutesConfig } from './config';
import { Container } from 'typescript-ioc';
import AppsRepository from '../repositories/apps-repository';
import KeysRepository from '../repositories/keys-repository';
import TagsRepository from '../repositories/tags-repository';
import PolicyRepository from '../repositories/policy-repository';
import SubjectExtractionRulesRepository from '../repositories/extraction-rules-repository';
Server.useIoC();
export default function configureRoutes(config: RoutesConfig): any {
const app = express();
Container.bind(AppsRepository).provider({ get: () => config.appsRepository });
Container.bind(KeysRepository).provider({ get: () => config.keysRepository });
Container.bind(TagsRepository).provider({ get: () => config.tagsRepository });
Container.bind(PolicyRepository).provider({ get: () => config.policyRepository });
Container.bind(SubjectExtractionRulesRepository).provider({
get: () => config.subjectExtractionRulesRepository,
});
const prefixes = [
{ from: 'keys', to: 'key' },
{ from: 'manifests', to: 'manifest' },
{ from: 'revision-history', to: 'revision-history' },