Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bypass prerender for farcaster integration routes #10421

Merged
merged 5 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions common_knowledge/Environment-Variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion common_knowledge/Twitter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<url>`
Expand Down
12 changes: 10 additions & 2 deletions packages/commonwealth/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion packages/commonwealth/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions packages/commonwealth/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand All @@ -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(
Expand Down Expand Up @@ -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(),
Expand Down
Loading