-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathindex.ts
More file actions
65 lines (57 loc) · 1.84 KB
/
index.ts
File metadata and controls
65 lines (57 loc) · 1.84 KB
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
import { createFile } from './utils'
import dotenv from 'dotenv'
import express from 'express'
import cors from 'cors'
import { FSXAContentMode, FSXAProxyApi, FSXARemoteApi, LogLevel } from '../src'
import { default as expressIntegration } from '../src/integrations/express'
require('cross-fetch/polyfill')
dotenv.config({ path: './dev/.env' })
const app = express()
const {
API_API_KEY,
API_NAVIGATION_SERVICE,
API_CAAS,
API_PROJECT_ID,
API_TENANT_ID,
API_REMOTES,
API_ENABLE_EVENT_STREAM,
} = process.env
const remoteApi = new FSXARemoteApi({
apikey: API_API_KEY!,
caasURL: API_CAAS!,
contentMode: FSXAContentMode.PREVIEW,
navigationServiceURL: API_NAVIGATION_SERVICE!,
projectID: API_PROJECT_ID!,
tenantID: API_TENANT_ID!,
remotes: JSON.parse(API_REMOTES || '{}'),
logLevel: LogLevel.INFO,
enableEventStream: !!API_ENABLE_EVENT_STREAM,
maxReferenceDepth: 0
})
app.use(cors())
app.use('/api', expressIntegration({ api: remoteApi }))
app.listen(3002, async () => {
console.log('Listening at http://localhost:3002')
try {
const locale = 'en_GB'
const proxyAPI = new FSXAProxyApi('http://localhost:3002/api', LogLevel.INFO)
const navigationResponse = await proxyAPI.fetchNavigation({ locale, initialPath: '/' })
createFile({
dirName: 'dev/dist',
fileName: `navigation.${locale}.json`,
content: navigationResponse,
})
if (navigationResponse) {
const pageInNavigationId = navigationResponse.seoRouteMap[navigationResponse.pages.index]
const { caasDocumentId } = navigationResponse.idMap[pageInNavigationId]
const homepageResponse = await proxyAPI.fetchElement({ id: caasDocumentId, locale })
createFile({
dirName: 'dev/dist',
fileName: `homepage.${locale}.json`,
content: homepageResponse,
})
}
} catch (e) {
console.log(e)
}
})