-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprerenderer.js
50 lines (40 loc) · 942 Bytes
/
prerenderer.js
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
const Server = require('./server')
// const PortFinder = require('portfinder')
class Prerenderer {
constructor(options) {
this._server = new Server(this)
this._options = options || {}
this._renderer = options.renderer
}
async initialize() {
await this._server.initialize()
await this._renderer.initialize()
return Promise.resolve()
}
destroy() {
this._renderer.close()
this._server.close()
}
getServer() {
return this._server
}
getRenderer() {
return this._renderer
}
getOptions() {
return this._options
}
modifyServer(server, stage) {
if (this._renderer.modifyServer) this._renderer.modifyServer(this, server, stage)
}
renderRoutes(routes) {
return this._renderer.renderRoutes(routes, this)
.then(renderedRoutes => {
renderedRoutes.forEach(rendered => {
rendered.route = decodeURIComponent(rendered.route)
})
return renderedRoutes
})
}
}
module.exports = Prerenderer