First you must initialize .env in /backend
cd backend
nano .env
the contents should be
OPENAI_API_KEY=
MONGO_DB_USERNAME=
MONGO_DB_PASSWORD=
SCRAPING_BEE_API_KEY=
enter relevant data
(Case sensitive) The mongoDB should be structured as such:
Backend_Database.Item
Backend_Database.Session
Backend_Database.System_Data
The System_Data collection must contain a single object that is configured like this.
{
"_id": <any-id>,
"ITEM_COUNTER": "0",
"NAME":"COUNTER_INFO",
"SESSION_COUNTER":"0"
}
npm install
npm start
The backend server and frontend server should be on the same machine
Backend Server Port: 5001
Frontend Server Port: 5173
NOTE: The backend server port should only be exposed to IPs that can use the API. The user of the API should be able to provide usage of the API through their own interface securely. Direct access to the API by the end user will result in the end user being able to view any session and item.
For simple demo purposes, you can use apache2 and reverse proxy port 5173.
NOTE: use prod fork if you're using apache2 instead of local development
Assuming Debian/Ubuntu Server install
edit
/etc/apache2/sites-available
it should be something similar to this:
<IfModule mod_ssl.c>
<VirtualHost *:443>
...
ProxyPreserveHost On
ProxyRequests Off
# Backend: proxy requests to the server running on port 5001
ProxyPass /api/ http://localhost:5001/
ProxyPassReverse /api/ http://localhost:5001/
# Frontend: proxy requests to the server running on port 5173
ProxyPass / http://localhost:5173/
ProxyPassReverse / http://localhost:5173/
</VirtualHost>
</IfModule>
make sure to
systemctl restart apache2
This document outlines the usage and functionality of the API endpoints available in this Express.js application.
Accepts an Excel file containing items data, processes it, and creates a new session in the database with items categorized as 'uncompleted_items'.
-
Method: POST
-
Endpoint:
/upload
-
Body: Form-data with key
excelFile
containing the Excel file to be uploaded. -
Content-Type: multipart/form-data
-
Content-Type: application/json
-
Body:
{
"_id": "<SessionID>",
"uncompleted_items": ["<ItemID1>", "<ItemID2>", "..."]
}
Accepts a sessionId
and an itemId
, checks if the item exists in the given session, and returns vendibility information for the item.
-
Method: GET
-
Endpoint:
/itemVendibility
-
Query Parameters:
-
sessionId
: The ID of the session to search within. -
itemId
: The ID of the item to analyze for vendibility.
-
Content-Type: application/json
-
Body: JSON object containing vendibility analysis results. The structure of this object depends on the implementation of
dataAnalysis()
function.
Retrieves all session IDs from the database along with their completed and uncompleted items.
-
Method: GET
-
Endpoint:
/getSessionIDs
-
Content-Type: application/json
-
Body:
{
"_ids": ["<SessionID1>", "<SessionID2>", "..."],
"completedItems": [[], [], "..."],
"uncompletedItems": [[], [], "..."]
}
All endpoints respond with appropriate HTTP status codes and error messages in case of failures. Common responses include:
-
Status 500 (Internal Server Error): When an unexpected condition was encountered.
-
Status 400 (Bad Request): When the request cannot be processed due to client-side errors (e.g., missing or invalid parameters).
Fetches item data if it exists within a specified session.
-
Method: GET
-
Endpoint:
/getItem
-
Query Parameters:
-
sessionId
: The ID of the session. -
itemId
: The ID of the item.
-
Content-Type: application/json
-
Body: JSON object containing the item's data if found, otherwise an error message.
Creates a new session in the database and returns its ID.
-
Method: POST
-
Endpoint:
/createSession
-
Content-Type: application/json
-
Body:
{
"sessionId": "<NewSessionID>"
}
Adds a new item to a specified session. The item data must be provided in JSON format.
-
Method: POST
-
Endpoint:
/addItem
-
Body: JSON object containing the item's data and the session ID it should be added to.
-
Content-Type: application/json
-
Body:
{
"success": true
}
- The JSON body for adding an item should match the specified format, with optional fields as necessary.
Returns table data for a specified session ID, including both completed and uncompleted items.
-
Method: GET
-
Endpoint:
/getTableFromSessionID
-
Query Parameters:
-
sessionID
: The ID of the session for which to retrieve table data.
-
Content-Type: application/json
-
Body: JSON object containing an array of items associated with the session.
All endpoints include error handling and will respond with appropriate HTTP status codes and messages in case of failures.
-
It's important to ensure that the Excel file follows the expected format and contains data starting from the specified rows and columns as assumed by the
/upload
endpoint logic. -
For the
/itemVendibility
endpoint, ensure that bothsessionId
anditemId
are provided as query parameters. -
This API assumes that the client is responsible for managing session lifecycle and item vendibility analysis workflow.
-
Ensure proper handling and validation of request data to avoid errors.
-
For
/addItem
, ensure the item JSON matches the expected schema as closely as possible to prevent insertion issues.