diff --git a/common_knowledge/Environment-Variables.md b/common_knowledge/Environment-Variables.md index 9acaf398f0f..4deb3b4905c 100644 --- a/common_knowledge/Environment-Variables.md +++ b/common_knowledge/Environment-Variables.md @@ -53,7 +53,6 @@ If you add a new environment variable, you must add documentation here. Please d - [NEXT_PUBLIC_RSA_PRIVATE_KEY](#next_public_rsa_private_key) - [NEXT_PUBLIC_RSA_PUBLIC_KEY](#next_public_rsa_public_key) - [NO_GLOBAL_ACTIVITY_CACHE](#no_global_activity_cache) -- [NO_PRERENDER](#no_prerender) - [NO_SSL](#no_ssl) - [NODE_ENV](#node_env) - [PGPASSWORD](#pgpassword) @@ -266,10 +265,6 @@ Mixpanel analytics tracking token for our live production site. If `true`, disables the initialization of `globalActivityCache.ts` from server. -## NO_PRERENDER - -In a production environment, prerender is only run from `commonwealth/server.ts` if this flag is false or blank. - ## NO_SSL Used and defined on-the-fly for the `start-external-webpack` package.json script. diff --git a/common_knowledge/Twitter.md b/common_knowledge/Twitter.md index 4d76bfc78a0..032b47c5cff 100644 --- a/common_knowledge/Twitter.md +++ b/common_knowledge/Twitter.md @@ -13,7 +13,7 @@ To get link previews, you will need to do the following: 3. Run against the built site in the packages/commonwealth folder with: ```bash - NO_PRERENDER=true NO_CLIENT_SERVER=true MIXPANEL_DEV_TOKEN=foo MIXPANEL_PROD_TOKEN=bar NODE_ENV=production npx tsx server.ts + NO_CLIENT_SERVER=true MIXPANEL_DEV_TOKEN=foo MIXPANEL_PROD_TOKEN=bar NODE_ENV=production npx tsx server.ts ``` 4. With the site running, query the link preview with `curl -G http://localhost:8080/` diff --git a/packages/commonwealth/main.ts b/packages/commonwealth/main.ts index fa7eae8f879..6d875753220 100644 --- a/packages/commonwealth/main.ts +++ b/packages/commonwealth/main.ts @@ -143,8 +143,16 @@ export async function main( app.use(passport.initialize()); app.use(passport.session()); - withPrerender && - app.use(prerenderNode.set('prerenderToken', config.PRERENDER_TOKEN)); + if (withPrerender) { + const rendererInstance = prerenderNode.set( + 'prerenderToken', + config.PRERENDER_TOKEN, + ); + app.use((req, res, next) => { + if (req.path.startsWith(`${api.integration.PATH}/farcaster/`)) next(); + else rendererInstance(req, res, next); + }); + } }; setupMiddleware(); diff --git a/packages/commonwealth/server.ts b/packages/commonwealth/server.ts index b2f4e9bf482..7477559be73 100644 --- a/packages/commonwealth/server.ts +++ b/packages/commonwealth/server.ts @@ -77,7 +77,9 @@ const start = async () => { await main(app, models, { port: config.PORT, withLoggingMiddleware: true, - withPrerender: config.APP_ENV === 'production' && !config.NO_PRERENDER, + withPrerender: + (config.APP_ENV === 'production' || config.APP_ENV === 'frick') && + !!config.PRERENDER_TOKEN, }) .then(async () => { isServiceHealthy = true; diff --git a/packages/commonwealth/server/config.ts b/packages/commonwealth/server/config.ts index 44b9cd792d3..2a95ecc9a08 100644 --- a/packages/commonwealth/server/config.ts +++ b/packages/commonwealth/server/config.ts @@ -10,7 +10,6 @@ const { TELEGRAM_BOT_TOKEN_DEV, SESSION_SECRET, SNAPSHOT_WEBHOOK_SECRET, - NO_PRERENDER: _NO_PRERENDER, NO_GLOBAL_ACTIVITY_CACHE, PRERENDER_TOKEN, GENERATE_IMAGE_RATE_LIMIT, @@ -28,8 +27,6 @@ const { DEV_MODULITH, } = process.env; -const NO_PRERENDER = _NO_PRERENDER; - const DEFAULTS = { GENERATE_IMAGE_RATE_LIMIT: '10', ACTIVE_COMMUNITIES_CACHE_TTL_SECONDS: '60', @@ -44,7 +41,6 @@ const DEFAULTS = { export const config = configure( { ...model_config, ...adapters_config }, { - NO_PRERENDER: NO_PRERENDER === 'true', NO_GLOBAL_ACTIVITY_CACHE: NO_GLOBAL_ACTIVITY_CACHE === 'true', PRERENDER_TOKEN, GENERATE_IMAGE_RATE_LIMIT: parseInt( @@ -109,7 +105,6 @@ export const config = configure( DEV_MODULITH: DEV_MODULITH === 'true', }, z.object({ - NO_PRERENDER: z.boolean(), NO_GLOBAL_ACTIVITY_CACHE: z.boolean(), PRERENDER_TOKEN: z.string().optional(), GENERATE_IMAGE_RATE_LIMIT: z.number().int().positive(),