-
Notifications
You must be signed in to change notification settings - Fork 50
/
index.ts
64 lines (57 loc) · 2.23 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import express = require('express');
import { Server } from 'typescript-rest';
import { KeysController } from './keys';
import { BulkKeysUpload } from './bulk-keys-upload';
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' },
{ from: 'dependents', to: 'dependent' },
{ from: 'resource/policy', to: 'resource/policy' },
];
prefixes.forEach((prefix) => {
app.all(`/${prefix.from}/*`, (req, res, next) => {
req.query['keyPath'] = req.params[0];
req.url = `/${prefix.to}`;
next();
});
});
Server.setFileDest('uploads/');
Server.buildServices(
app,
AppsController,
TagsController,
SearchController,
BulkKeysUpload,
SchemaController,
KeysController,
PolicyController,
ResourcePolicyController,
SubjectExtractionRulesController,
);
return app;
}