Skip to content
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
2 changes: 2 additions & 0 deletions embedding_qs_series_2_api_use_cases/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions recipe-portal/app/api/call/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function getCachedToken(): { token: string; clientId: string } | null {

export async function POST(request: Request) {
try {
const { endpoint, method, parameters = {}, requestBody } = await request.json();
const { endpoint, method, parameters = {}, requestBody, baseURL: providedBaseURL } = await request.json();

if (!endpoint) {
return NextResponse.json(
Expand All @@ -76,9 +76,11 @@ export async function POST(request: Request) {
);
}

// Build the full URL
const baseURL = process.env.SIGMA_BASE_URL || 'https://aws-api.sigmacomputing.com/v2';
// Build the full URL - use provided baseURL to prevent race conditions, fallback to environment/default
const baseURL = providedBaseURL || process.env.SIGMA_BASE_URL || 'https://aws-api.sigmacomputing.com/v2';
let url = `${baseURL}${endpoint}`;

console.log(`API Call: ${method} ${url} (baseURL from auth config: ${baseURL})`);

// Add query parameters
if (parameters.query && Object.keys(parameters.query).length > 0) {
Expand Down
12 changes: 11 additions & 1 deletion recipe-portal/app/api/code/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,26 @@ export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const filePath = searchParams.get('path');

console.log('=== CODE API DEBUG ===');
console.log('Received filePath:', filePath);
console.log('Process CWD:', process.cwd());

if (!filePath) {
return NextResponse.json(
{ error: 'File path is required' },
{ status: 400 }
);
}

// Force the file path to be relative to our current working directory
const relativePath = filePath.replace(/^.*recipes\//, 'recipes/');
const correctedPath = path.join(process.cwd(), relativePath);

console.log('Corrected path:', correctedPath);

// Security check: ensure the file is within the recipes directory
const recipesPath = path.join(process.cwd(), 'recipes');
const resolvedPath = path.resolve(filePath);
const resolvedPath = path.resolve(correctedPath);
const resolvedRecipesPath = path.resolve(recipesPath);

if (!resolvedPath.startsWith(resolvedRecipesPath)) {
Expand Down
2 changes: 1 addition & 1 deletion recipe-portal/app/api/download-stream/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ envLines.forEach(line => {
// Token caching
function getTokenCacheFile(clientId: string) {
const configHash = clientId ? clientId.substring(0, 8) : "default";
return path.join(os.tmpdir(), `sigma-portal-token-${configHash}.json`);
return path.join(os.tmpdir(), "sigma-portal-token-" + configHash + ".json");
}

function getCachedToken(): { token: string; clientId: string } | null {
Expand Down
Loading