Skip to content

Commit

Permalink
Fix prerendering for Googlebot (#6170)
Browse files Browse the repository at this point in the history
* update + set up prerender

* yarn.lock

* use chromium

* yarn.lock

* revert chromium + setup prerender.io

* remove chromium

* try using 127.0.0.1

* prerender in-memory cache

* prerender debugging log

* prerender token

* prerender token

* yarn.lock

* prerender only when NODE_ENV=production

* prerender only on commonwealth.im

* yarn.lock
  • Loading branch information
timolegros authored Jan 5, 2024
1 parent 9267996 commit dd7a963
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 245 deletions.
3 changes: 1 addition & 2 deletions packages/commonwealth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@
"passport-jwt": "^4.0.0",
"passport-magic": "^1.0.0",
"path-browserify": "^1.0.1",
"prerender": "^5.6.0",
"prerender-node": "^3.2.5",
"prerender-node": "^3.7.0",
"process": "^0.11.10",
"quill": "^1.3.7",
"quill-image-drop-and-paste": "^1.0.4",
Expand Down
17 changes: 6 additions & 11 deletions packages/commonwealth/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ import * as v8 from 'v8';
import setupErrorHandlers from '../common-common/src/scripts/setupErrorHandlers';
import {
DATABASE_CLEAN_HOUR,
PRERENDER_TOKEN,
RABBITMQ_URI,
REDIS_URL,
ROLLBAR_ENV,
ROLLBAR_SERVER_TOKEN,
SERVER_URL,
SESSION_SECRET,
TBC_BALANCE_TTL_SECONDS,
VULTR_IP,
Expand All @@ -45,7 +47,6 @@ import setupAPI from './server/routing/router';
import { sendBatchedNotificationEmails } from './server/scripts/emails';
import setupAppRoutes from './server/scripts/setupAppRoutes';
import expressStatsdInit from './server/scripts/setupExpressStats';
import setupPrerenderServer from './server/scripts/setupPrerenderService';
import setupServer from './server/scripts/setupServer';
import BanCache from './server/util/banCheckCache';
import setupCosmosProxy from './server/util/cosmosProxy';
Expand Down Expand Up @@ -103,7 +104,6 @@ async function main() {
process.exit(rc);
}

const WITH_PRERENDER = process.env.WITH_PRERENDER;
const NO_PRERENDER = process.env.NO_PRERENDER || NO_CLIENT_SERVER;

const SequelizeStore = SessionSequelizeStore(session.Store);
Expand Down Expand Up @@ -196,7 +196,10 @@ async function main() {
app.use(sessionParser);
app.use(passport.initialize());
app.use(passport.session());
app.use(prerenderNode.set('prerenderServiceUrl', 'http://localhost:3000'));

if (!DEV && !NO_PRERENDER && SERVER_URL.includes('commonwealth.im')) {
app.use(prerenderNode.set('prerenderToken', PRERENDER_TOKEN));
}
};

const templateFile = (() => {
Expand All @@ -209,14 +212,6 @@ async function main() {

const sendFile = (res) => res.sendFile(`${__dirname}/build/index.html`);

// Only run prerender in DEV environment if the WITH_PRERENDER flag is provided.
// On the other hand, run prerender by default on production.
if (DEV) {
if (WITH_PRERENDER) setupPrerenderServer();
} else {
if (!NO_PRERENDER) setupPrerenderServer();
}

setupMiddleware();
setupPassport(models);

Expand Down
2 changes: 2 additions & 0 deletions packages/commonwealth/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,5 @@ export const MEMBERSHIP_REFRESH_TTL_SECONDS = process.env
export const TBC_BALANCE_TTL_SECONDS = process.env.TBC_BALANCE_TTL_SECONDS
? parseInt(process.env.TBC_BALANCE_TTL_SECONDS, 10)
: 300;

export const PRERENDER_TOKEN = process.env.PRERENDER_TOKEN;
35 changes: 0 additions & 35 deletions packages/commonwealth/server/scripts/setupPrerenderService.ts

This file was deleted.

Loading

0 comments on commit dd7a963

Please sign in to comment.