-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
94 lines (83 loc) · 3.02 KB
/
server.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* -----------------------------------------------------------------------------
* Copyright (c) 2023, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* No Patent Rights, Trademark Rights and/or other Intellectual Property
* Rights other than the rights under this license are granted.
* All other rights reserved.
*
* For any other rights, a separate agreement needs to be closed.
*
* For more information please contact:
* Fraunhofer FOKUS
* Kaiserin-Augusta-Allee 31
* 10589 Berlin, Germany
* https://www.fokus.fraunhofer.de/go/fame
* -----------------------------------------------------------------------------
*/
import cors from 'cors'
import dotenv from 'dotenv'
dotenv.config()
import express from 'express'
import path from 'path'
import { CONFIG } from './src/config/config'
import configureDependencies from './src/config/configureDeps'
import EntryPointController from './src/controllers/EntryPointController'
import errHandler from './src/handlers/ErrorHandler'
export const ROOT_DIR = process.cwd()
//@ts-ignore
global.__basedir = __dirname
const app = express()
const PORT = CONFIG.PORT
app.use(function (req, res, next) {
res.header(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept, Authorization, x-access-token, x-token-renewed, x-api-key'
);
res.header(
'Access-Control-Allow-Methods',
'GET,PUT,POST,DELETE,PATCH,OPTIONS'
);
next();
});
app.use(cors())
app.use(express.json())
const basePath = CONFIG.BASE_PATH || '/core';
const EXCLUDED_PATHS = [
`${basePath}/swagger`,
`${basePath}/roles`,
`${basePath}/roles/:id`,
`${basePath}/users/verifyToken/:tokenId`,
`${basePath}/mgmt/consumers/:id/confirm`,
`${basePath}/sso/oidc`,
`${basePath}/sso/success`,
`${basePath}/sso/oidc/backend/login`,
`${basePath}/sso/oidc/access_token_by_code`,
`${basePath}/sso/oidc/broker/logout`,
`${basePath}/sso/oidc/broker/logout/redirect`,
`/health`
]
app.get('/health', (req, res) => res.send('OK'))
app.set('views', path.join(ROOT_DIR, '/pages'))
app.set('view engine', 'ejs')
app.use(basePath, EntryPointController)
app.use(errHandler);
configureDependencies(app, EXCLUDED_PATHS).then(() =>
app.listen(PORT, () => {
console.info(`Listening for core on port ${PORT}`)
})
).catch((err) => {
console.error(JSON.stringify(err))
})