If you're deploying on a traditional server with Nginx + PM2 (as shown in your docs), use this Nginx configuration instead of Vercel middleware.
Edit your Nginx site configuration:
sudo nano /etc/nginx/sites-available/stairs
# or
sudo nano /etc/nginx/sites-available/portal.stairs.org.inAdd this location block BEFORE your general location / block:
# Bot detection for event pages - MUST BE FIRST
location ~ ^/event/([^/]+)$ {
set $uniqueId $1;
set $is_bot 0;
# Check if user-agent indicates a bot/crawler
if ($http_user_agent ~* "(bot|crawler|spider|scraper|facebookexternalhit|facebookcatalog|Twitterbot|Twitter|LinkedInBot|LinkedIn|WhatsApp|whatsapp|Slackbot|Slack|TelegramBot|Telegram|SkypeUriPreview|Discordbot|Discord|Googlebot|Google|Bingbot|Bing|Slurp|DuckDuckBot|Baiduspider|YandexBot|Sogou|Exabot|facebot|ia_archiver|Pinterestbot|Pinterest|redditbot|reddit|Applebot|Line|Kik|Viber|WeChat|Snapchat|TikTok|PostmanRuntime|curl|wget)") {
set $is_bot 1;
}
# Redirect bots to preview endpoint
if ($is_bot = 1) {
rewrite ^/event/(.+)$ /api/events/preview/$1 permanent;
break;
}
# For regular users, serve the React app
root /var/www/stairs-new/frontend/dist;
try_files /index.html =404;
}sudo nginx -tsudo systemctl reload nginxTest with curl:
curl -I -H "User-Agent: facebookexternalhit/1.1" \
https://portal.stairs.org.in/event/EVT-0051-OT-DL-271225Should return: Location: /api/events/preview/EVT-0051-OT-DL-271225
See nginx-event-preview.conf for a complete example configuration.
If you're actually using Vercel for deployment:
- Keep the
middleware.jsandvercel.jsonas-is - The Vercel configuration will handle bot routing automatically
- Just ensure
FRONTEND_URLenvironment variable is set
Check your domain:
- If
portal.stairs.org.inis on Vercel → Use Vercel config (middleware.js) - If it's on a traditional server → Use Nginx config above