This project provides an API for performing background changes on images using a React frontend, Flask backend, and webhook integration.
- Node.js: Version 20 installed using Node Version Manager (nvm).
- npm or yarn for dependency management.
-
Install Node.js v20:
nvm install 20 nvm use 20
-
Navigate to the frontend directory:
cd bg_change_frontend -
Install dependencies:
npm install # or yarn install -
Start the development server:
npm run dev # or yarn devThe frontend will be available at
http://localhost:5173.
Update the webhook URLs in src/App.tsx to point to your ngrok forwarding URL:
- Locate and replace occurrences of
ngrok-free.appwith your ngrok URL.
For example, update:to:webhookUrl: "https://c184-219-91-134-123.ngrok-free.app/api/webhook";
webhookUrl: "https://your-ngrok-url.ngrok-free.app/api/webhook";
- Python 3.x
- pip (Python package installer)
- Virtual environment (recommended)
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Navigate to the backend directory:
cd bg_change_webhook -
Install dependencies:
pip install -r requirements.txt
-
Create a
.envfile in the backend directory with your credentials:CLIENT_ID=your_client_id CLIENT_SECRET=your_client_secret
-
Start the Flask server:
python app.py
The backend will be available at
http://localhost:3008.
Webhook integration uses ngrok to provide a public URL for your backend.
-
Install ngrok:
- Download ngrok from the official website.
- Create a free ngrok account.
- Follow the installation instructions for your operating system.
-
Authenticate ngrok:
ngrok config add-authtoken your_auth_token
-
Start ngrok to forward the backend port:
ngrok http 3008
-
Copy the generated forwarding URL (e.g.,
https://your-ngrok-url.ngrok-free.app) and:- Update the webhook URL in your frontend configuration (see Frontend Setup).
- Ensure the backend webhook endpoint is accessible through this URL.
{
"canvas_size": "3840x3840",
"template_url": "https://d3c24lvfmudc1v.cloudfront.net/public/background_change/ROne.png",
"modify_template_size": "3830x3830",
"overlay_template_x": 5,
"overlay_template_y": 5,
"origin_img": "https://drz0f01yeq1cx.cloudfront.net/1711939252580-7e40bd1a-e480-42ed-8585-3f9ffccf6bdb-5822.png",
"modify_origin_img_size": "3830x2145",
"overlay_origin_x": 5,
"overlay_origin_y": 849
}{
"color_code": "#c9aafb",
"canvas_size": "3840x3840",
"origin_img": "https://drz0f01yeq1cx.cloudfront.net/1712132369637-69a946c0-b2a7-4fe6-92c8-2729b36cc13e-0183.png",
"modify_origin_img_size": "3060x3824",
"overlay_origin_x": 388,
"overlay_origin_y": 8
}- Ensure both frontend and backend servers are running simultaneously.
- The ngrok URL changes with every restart (unless you have a paid plan). Update it in the frontend whenever it changes.
- Keep sensitive credentials such as
CLIENT_IDandCLIENT_SECRETsecure and avoid committing them to version control. - Troubleshoot CORS and firewall issues if the API doesn't work as expected.
- CORS Issues: Verify the backend's CORS settings.
- ngrok Connectivity Problems: Ensure the ngrok authtoken is correctly configured.