Skip to content
Open
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: 5 additions & 0 deletions productionized/pulse-fetch/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
# Get one at: https://www.firecrawl.dev/
FIRECRAWL_API_KEY=your-firecrawl-api-key-here

# Firecrawl API Base URL (optional)
# Custom base URL for Firecrawl API (useful for self-hosted instances)
# Defaults to: https://api.firecrawl.dev
# FIRECRAWL_API_BASE_URL=https://api.firecrawl.dev

# BrightData API Key (optional)
# Get one at: https://brightdata.com/ from the Web Unlocker product
# Just provide the token - 'Bearer ' will be prepended automatically
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
// Validate and cache the base URL at module load time
const getBaseUrl = (): string => {
const baseUrl = process.env.FIRECRAWL_API_BASE_URL || 'https://api.firecrawl.dev';

// Validate baseUrl to prevent injection attacks
if (
baseUrl &&
(!/^https?:\/\/[^\\]+$/.test(baseUrl) || baseUrl.includes('..'))
) {
throw new Error('Invalid FIRECRAWL_API_BASE_URL');
}

return baseUrl;
};

const FIRECRAWL_BASE_URL = getBaseUrl();

export async function scrapeWithFirecrawl(
apiKey: string,
url: string,
Expand All @@ -13,7 +30,7 @@ export async function scrapeWithFirecrawl(
error?: string;
}> {
try {
const response = await fetch('https://api.firecrawl.dev/v1/scrape', {
const response = await fetch(`${FIRECRAWL_BASE_URL}/v1/scrape`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
Loading