Skip to content

Commit

Permalink
Hosting backend server
Browse files Browse the repository at this point in the history
  • Loading branch information
Levironexe committed Oct 17, 2024
1 parent 14eb3c5 commit 8af9a05
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 44 deletions.
1 change: 0 additions & 1 deletion .env

This file was deleted.

6 changes: 3 additions & 3 deletions app/api/backend.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import mongoose from 'mongoose';
import cors from 'cors';
import path from 'path';
import multer from 'multer'; // Use multer for file uploads
import ContractNameDB from './contractDetail.mjs'; // Import your Mongoose model
import ContractNameDB from './schema.mjs'; // Import your Mongoose model

const app = express(); // Initialize Express app

Expand Down Expand Up @@ -50,7 +50,7 @@ app.post('/contract-upload', upload.single('contractFile'), (req, res) => {
});

// Route: Contract Analyze and Save Project Name
app.post('/contract-analyze', async (req, res) => {
app.post('/contract-analyze',upload.single('projectName'), async (req, res) => {
try {
const { projectName } = req.body; // Access project name from the request body

Expand All @@ -74,4 +74,4 @@ app.post('/contract-analyze', async (req, res) => {
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
console.log(`Backend server running on port ${PORT}`);
});
});
1 change: 0 additions & 1 deletion app/api/contractDetail.mjs → app/api/schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,3 @@ const ScanResultSchema = new mongoose.Schema({
createdAt: { type: Date, default: Date.now }, // Timestamp of the scan
});*/}


77 changes: 45 additions & 32 deletions components/button/upload-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ const UploadForm = ({style, title}: UploadFormProps) => {
const [messageName, setMessageName] = useState<string>('');
const {isScanning, startScanning} = useScanning(); // Destructuring scanning state and key press handler from custom hook
const [openUpload, setOpenUpload] = useState(false);
const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:5000';

const API_URL = process.env.NEXT_PUBLIC_API_URL;
const handleProjectNameChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setProjectName(event.target.value); // Update project name
};
Expand Down Expand Up @@ -80,37 +79,51 @@ const UploadForm = ({style, title}: UploadFormProps) => {
};

// Handle Form Submission and File Upload
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault(); // Prevent page refresh


// Validate project name
if (!projectName.trim()) {
setMessageName('Please enter a project name before uploading.');
return;
} else {
setMessageName('');
}
if (!contractFile) {
setMessage('Please select a file to upload.');
return;
}
// Validate file selection
const formData = new FormData();
formData.append('projectName', projectName); // Add the project name
try {
console.log(API_URL);
const submit = await axios.post(`${API_URL}/contract-analyze`,
formData, {
headers: { 'Content-Type': 'multipart/form-data' },
});
if (submit.status === 200) {
startScanning('')
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault(); // Prevent page refresh

// Validate project name
if (!projectName.trim()) {
setMessageName('Please enter a project name before uploading.');
return;
}
setMessageName(''); // Clear any previous error messages

// Validate file selection
if (!contractFile) {
setMessage('Please select a file to upload.');
return;
}
} catch {
setMessage("Something went wrong"); // Show backend message
}
};

const formData = new FormData();
formData.append('projectName', projectName); // Add the project name
formData.append('contractFile', contractFile); // Add the contract file

try {
console.log(`API URL: ${API_URL}`);

const response = await axios.post(`${API_URL}/contract-analyze`, formData, {
headers: { 'Content-Type': 'multipart/form-data' },
});

if (response.status === 200) {
setMessage('Upload successful! The scan has started.');
startScanning(''); // Call the scanning function
} else {
setMessage(`Unexpected response: ${response.statusText}`);
}
} catch (error: any) {
console.error('Error during submission:', error);
if (error.response) {
// If the backend sent an error response
setMessage(`Error: ${error.response.data.message || 'Something went wrong.'}`);
} else {
// If the error is network-related or something else
setMessage('Unable to connect to the backend. Please try again.');
}
}
};



return (
Expand Down
2 changes: 1 addition & 1 deletion components/section/full-screen-video-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react' // Importing React to create a functional component.
const Video = () => {
return (
// Section for video display, hidden on smaller screens (lg:hidden).
<section className="hidden lg:flex xl:px-0 z-50 relative">
<section className="hidden lg:flex xl:px-0 z-10 relative">
<div className="w-full">
{/* Video element that plays automatically, loops, and is muted */}
<video
Expand Down
2 changes: 1 addition & 1 deletion components/section/youtube-reference-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ const YTRefSection = () => {
)
}

export default YTRefSection
export default YTRefSection
5 changes: 0 additions & 5 deletions vercel.json

This file was deleted.

0 comments on commit 8af9a05

Please sign in to comment.