API 405
Unanswered
Selkirk Rex posted this in #help-forum
Selkirk RexOP
Hey Guys,
I am having an issue getting my NextJS 14 API's working on production, I have the correct baseURL, have followed every stackoverflow and reddit psot. Have even reached out to Vercel support and can't figure out a solution.. All environment variables are in as well.
See below code, any help would be greatly appreciated.
Frontend is txt due to size.
I am having an issue getting my NextJS 14 API's working on production, I have the correct baseURL, have followed every stackoverflow and reddit psot. Have even reached out to Vercel support and can't figure out a solution.. All environment variables are in as well.
See below code, any help would be greatly appreciated.
import { connectToDatabase } from '../../../../server/db';
export default async function handler(req, res) {
if (req.method !== 'POST') {
res.setHeader('Access-Control-Allow-Origin', '*'); // Adjust accordingly for security
res.setHeader('Access-Control-Allow-Methods', ' POST');
return res.status(405).json({ message: 'Method not allowed' });
}
const { name, description, start_date, end_date, original_contract_value, revised_contract_value, sc_threshold, lien_expiry, cos_to_date, original_duration, impact_days, revised_duration } = req.body;
// Extend this check to ensure all required fields are provided
if (!name || !description || !start_date || !end_date || !original_contract_value) {
return res.status(400).json({ message: 'Missing required fields' });
}
try {
const pool = await connectToDatabase();
const query = `
INSERT INTO projects (name, description, start_date, end_date, original_contract_value, revised_contract_value, sc_threshold, lien_expiry, cos_to_date, original_duration, impact_days, revised_duration)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
`;
const [result] = await pool.query(query, [name, description, start_date, end_date, original_contract_value, revised_contract_value, sc_threshold, lien_expiry, cos_to_date, original_duration, impact_days, revised_duration]);
// Assuming result.insertId is available and correct
res.status(201).json({ message: 'Project created successfully', projectId: result.insertId });
} catch (error) {
console.error('Failed to create project:', error);
// Consider logging the error to a file or external service if needed
res.status(500).json({ message: 'Failed to create project', error: 'An unexpected error occurred' });
}
}Frontend is txt due to size.