Olá, estou tentando colocar um parametro dinamico na minha API , funciona no localhost, porém em produção, ele recebe o parametro, mas não executa como deveria e retorna todos os dados e o filtrado no parametro.
import { NextResponse } from ‘next/server’;
import { getDbConnection } from ‘…/…/…/config/dbConfig’;
export async function GET(req: Request) {
try {
const url = new URL(req.url);
const nome = url.searchParams.get(‘NOME’);
console.log(‘Parametro NOME:’, nome);
const pool = await getDbConnection();
const query = 'SELECT * FROM PERSONAGENS WHERE NOME = @nome';
const result = await pool.request()
.input('NOME', nome)
.query(query);
// Processar os resultados
return NextResponse.json(result.recordset.map(item => ({
...item,
IMGS: JSON.parse(item.IMGS.replace(/\\/g, '')) // Tratando imagens no JSON
}))); // Retorna os dados
} catch (error) {
console.error(‘Erro ao buscar dados:’, error);
return NextResponse.json({ error: ‘Erro ao buscar os dados’ }, { status: 500 });
}
}
Hi @geisbelly! Posts usually get more attention if translated into a language the majority of community members have in common. I translated your post to English so more people can find and understand your issue.
Hello, I’m trying to add a dynamic parameter to my API. It works on localhost, but in production, it receives the parameter but doesn’t execute as it should and returns all the data and the filtered data in the parameter.
import { NextResponse } from ‘next/server’;
import { getDbConnection } from ‘…/…/…/config/dbConfig’;
export async function GET(req: Request) {
try {
const url = new URL(req.url);
const nome = url.searchParams.get(‘NOME’);
console.log(‘Parametro NOME:’, nome);
const pool = await getDbConnection();
const query = 'SELECT * FROM PERSONAGENS WHERE NOME = @nome';
const result = await pool.request()
.input('NOME', nome)
.query(query);
// Process the results
return NextResponse.json(result.recordset.map(item => ({
...item,
IMGS: JSON.parse(item.IMGS.replace(/\\/g, '')) // Processing images in JSON
}))); // Returns the data
} catch (error) {
console.error(‘Error fetching data:’, error);
return NextResponse.json({ error: ‘Error fetching data’ }, { status: 500 });
}
}