Skip to content

Commit d0a16ff

Browse files
authored
Merge pull request #17 from bitrise-io/integrations-ssr-enablement
Integrations ssr enablement
2 parents d167aba + 20a794e commit d0a16ff

30 files changed

Lines changed: 2173 additions & 199 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
node_modules
55
yarn-error.log
66
yarn.lock
7+
/build
78
/dist/*.js
89
/dist/*.LICENSE.txt
910
/dist/maintenance.html
11+
/dist/integrations.html
12+
/dist/integrations/*
1013
/dist/images/*
1114
/career-maps.json
1215
/changelog.json

build.js

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const path = require('path');
12
const webpack = require('webpack');
23
const webpackConfigBuilder = require('./webpack.config.js');
34

@@ -14,11 +15,38 @@ const webpackBuild = (config) =>
1415

1516
const { build: buildMaintenance } = require('./src/js/maintenance/build.js');
1617

18+
const buildPath = path.resolve(__dirname, 'build');
19+
20+
const ssrWebpackConfig = {
21+
target: 'node',
22+
mode: 'production',
23+
entry: {
24+
integrations: path.resolve(__dirname, 'src/js/integrations/ssr.js'),
25+
},
26+
output: {
27+
path: buildPath,
28+
filename: '[name]-ssr.js',
29+
library: { type: 'commonjs2' },
30+
},
31+
resolve: {
32+
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
33+
},
34+
externals: ({ request }, callback) => {
35+
if (request && /^[a-zA-Z@]/.test(request)) {
36+
callback(null, `commonjs2 ${request}`);
37+
} else {
38+
callback();
39+
}
40+
},
41+
};
42+
1743
const build = async () => {
44+
const webpackConfig = webpackConfigBuilder('production');
45+
1846
// Build project with Webpack
1947
let webpackStats;
2048
try {
21-
webpackStats = await webpackBuild(webpackConfigBuilder('production'));
49+
webpackStats = await webpackBuild(webpackConfig);
2250
} catch (error) {
2351
webpackStats = error;
2452
}
@@ -29,9 +57,34 @@ const build = async () => {
2957
process.stdout.write(`Webpack build completed successfully:\n${webpackStats.toString({ colors: true })}\n\n`);
3058
}
3159

60+
/** @type {webpack.Stats} */
61+
let webpackSsrStats;
62+
try {
63+
webpackSsrStats = await webpackBuild(ssrWebpackConfig);
64+
} catch (error) {
65+
webpackSsrStats = error;
66+
}
67+
if (webpackSsrStats.hasErrors()) {
68+
process.stderr.write(`SSR Webpack build failed:\n${webpackSsrStats.toString({ colors: true })}\n\n`);
69+
throw new Error('SSR Webpack build failed');
70+
} else {
71+
process.stdout.write(
72+
`SSR Webpack build completed successfully:\n${webpackSsrStats.toString({ colors: true })}\n\n`,
73+
);
74+
}
75+
76+
// eslint-disable-next-line global-require
77+
const { render: renderIntegrations } = require('./build/integrations-ssr.js');
78+
await renderIntegrations({
79+
destination: path.resolve(__dirname, webpackConfig.output.path),
80+
templateHostname: 'bitrise.io',
81+
});
82+
3283
// Build maintenance.html (depends on dist/404.js from webpack)
33-
await buildMaintenance();
34-
process.stdout.write('Maintenance page build completed successfully.\n\n');
84+
await buildMaintenance({
85+
distPath: path.resolve(__dirname, webpackConfig.output.path),
86+
srcPath: path.resolve(__dirname, 'src'),
87+
});
3588
};
3689

3790
build().catch((error) => {

index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ async function importWorker(workerName, workerPath) {
2424
const workerContent = (await fs.promises.readFile(workerPath, 'utf8'))
2525
.toString()
2626
.replaceAll("ORIGIN_HOST = 'bitrise.io'", `ORIGIN_HOST = '${webflowDomain}'`)
27+
.replaceAll("PRERENDERED_HOST = 'webflow-scripts.bitrise.io'", `PRERENDERED_HOST = '${hostname}:${port}'`)
2728
.replaceAll(
2829
`urlObject.hostname = 'web-cdn.bitrise.io';`,
2930
`urlObject.hostname = '${hostname}'; urlObject.port = ${port}; urlObject.search = 'cdn=1';`, // TODO: make this switchable
@@ -160,7 +161,11 @@ const { generateMaintenanceHtml } = require('./src/js/maintenance/build.js');
160161
app.get('/maintenance.html', async (req, res) => {
161162
try {
162163
// In dev, skip JS inlining — style-loader's HMR runtime needs publicPath from script.src
163-
const html = await generateMaintenanceHtml({ skipJs: true });
164+
const html = await generateMaintenanceHtml({
165+
skipJs: true,
166+
distPath: path.resolve(__dirname, 'dist'),
167+
srcPath: path.resolve(__dirname, 'src'),
168+
});
164169
res.setHeader('Content-Type', 'text/html');
165170
res.end(html);
166171
} catch (error) {
@@ -183,7 +188,14 @@ app.get(/\/.*/, async (req, res) => {
183188
res.statusCode = 200;
184189
const extname = path.extname(urlObject.pathname);
185190
if (extname === '.js') res.setHeader('Content-Type', 'text/javascript');
186-
if (extname === '.html') res.setHeader('Content-Type', 'text/html');
191+
if (extname === '.html') {
192+
res.setHeader('Content-Type', 'text/html');
193+
let body = content.toString();
194+
body = body.replace("document.location.host === 'test-e93bfd.webflow.io'", 'true');
195+
body = body.replace('https://webflow-scripts.bitrise.io/', '/');
196+
res.end(body);
197+
return;
198+
}
187199
if (extname === '.json') res.setHeader('Content-Type', 'application/json');
188200

189201
process.stdout.write(`[info] Serving local file ${filePath}\n`);

0 commit comments

Comments
 (0)