-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
59 lines (46 loc) · 1.62 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
import cors from 'cors';
import express from 'express';
import helmet from 'helmet';
import { serve, setup } from 'swagger-ui-express';
import { errorHandler, provider } from '@overture-stack/lyric';
import { appConfig, getServerConfig } from './config/app.js';
import swaggerDoc from './config/swagger.js';
import healthRouter from './routes/health.js';
import pingRouter from './routes/ping.js';
const { allowedOrigins, port, corsEnabled } = getServerConfig();
const lyricProvider = provider(appConfig);
// Create Express server
const app = express();
app.use(helmet());
app.use(
cors({
origin: function (origin, callback) {
// If CORS is disabled, allow the request regardless of the origin
if (!corsEnabled) {
return callback(null, true);
}
// If the origin is in the allowed origins list, allow the request
if (origin && allowedOrigins.indexOf(origin) !== -1) {
return callback(null, true);
}
const msg = 'The CORS policy for this site does not allow access from the specified Origin.';
return callback(new Error(msg), false);
},
}),
);
// Ping Route
app.use('/ping', pingRouter);
// Lyric Routes
app.use('/audit', lyricProvider.routers.audit);
app.use('/category', lyricProvider.routers.category);
app.use('/data', lyricProvider.routers.submittedData);
app.use('/dictionary', lyricProvider.routers.dictionary);
app.use('/submission', lyricProvider.routers.submission);
// Swagger route
app.use('/api-docs', serve, setup(swaggerDoc));
app.use('/health', healthRouter);
app.use(errorHandler);
// running the server
app.listen(port, () => {
console.log(`Starting ExpressJS server on port ${port}`);
});