-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathssr.js
More file actions
45 lines (35 loc) · 1.39 KB
/
ssr.js
File metadata and controls
45 lines (35 loc) · 1.39 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
/*
* Copyright (c) 2022, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path')
const {getRuntime} = require('@salesforce/pwa-kit-runtime/ssr/server/express')
const pkg = require('../package.json')
const options = {
// The build directory (an absolute path)
buildDir: path.resolve(process.cwd(), 'build'),
// The cache time for SSR'd pages (defaults to 600 seconds)
defaultCacheTimeSeconds: 600,
// The port that the local dev server listens on
port: 3000,
// The protocol on which the development Express app listens.
// Note that http://localhost is treated as a secure context for development,
// except by Safari.
protocol: 'http',
mobify: pkg.mobify
}
const runtime = getRuntime()
const {handler} = runtime.createHandler(options, (app) => {
// Handle the redirect from SLAS as to avoid error
app.get('/callback?*', (req, res) => {
res.send()
})
app.get('/favicon.ico', runtime.serveStaticFile('static/favicon.ico'))
app.get('*', runtime.render)
})
// SSR requires that we export a single handler function called 'get', that
// supports AWS use of the server that we created above.
exports.get = handler