-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.ts
50 lines (38 loc) · 1.3 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
import { join } from 'path';
import { writeFile } from 'fs';
import * as compression from 'compression';
import * as express from 'express';
import * as cors from 'cors';
import { EmbedConfig } from './src/embed.config';
// Express server
const server = express();
server.use(cors());
server.use(compression());
const router = express.Router();
const HOST = process.env.HOST || 'localhost';
const PORT = Number(process.env.PORT) || 4200;
const BASE_HREF = process.env.BASE_HREF || '/';
const SERVICE_URL = process.env.SERVICE_URL || 'http://localhost:9000';
const UI_URL = process.env.UI_URL || 'http://localhost:3000';
const VIVO_URL = process.env.VIVO_URL || 'https://scholars.library.tamu.edu/vivo';
const embedConfig: EmbedConfig = {
serviceUrl: SERVICE_URL,
uiUrl: UI_URL,
vivoUrl: VIVO_URL
};
const DIST_FOLDER = join(process.cwd(), 'dist');
writeFile('./dist/embedConfig.json', JSON.stringify(embedConfig), (err) => {
if (err) {
console.log(err);
} else {
console.log('Static runtime embed config created:');
console.log(embedConfig);
}
});
router.get('*.*', express.static(DIST_FOLDER, {
maxAge: '1y'
}));
server.use(BASE_HREF, router);
server.listen(PORT, () => {
console.log(`Node Express server listening on http://${HOST}:${PORT}${BASE_HREF}`);
});