forked from geyserfund/geyser-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
36 lines (31 loc) · 946 Bytes
/
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
/* eslint-disable @typescript-eslint/no-var-requires */
const express = require('express')
const handler = require('serve-handler')
const prerender = require('prerender-node')
console.log(
`ENV VAR CHECK:\n\tPORT: ${
process.env.PORT
}\nPRERENDER_TOKEN: not null -> ${Boolean(process.env.PRERENDER_TOKEN)}`,
)
const PORT = process.env.PORT || 3000
const app = express()
app.use(
prerender
.set('prerenderToken', process.env.PRERENDER_TOKEN)
.set('afterRender', (err) => {
// If the request to prerender server fails, just return the normal static files.
if (err) {
console.error('Prerender Error', err)
return { cancelRender: true }
}
}),
)
app.use((request, response) => {
return handler(request, response, {
public: './dist',
rewrites: [{ source: '*', destination: '/index.html' }],
})
})
app.listen(PORT, () => {
console.log(`Geyser app listening on port ${PORT}`)
})