This Node.js application serves as a simple screenshot capture service using Puppeteer and Express.js. It listens for HTTP requests on different routes, captures full-page screenshots of specified web pages, and returns them as image responses.
To use this service, follow these steps:
-
Clone the repository:
git clone https://github.com/yourusername/your-repo.git cd your-repo
-
Install the dependencies:
npm install
-
Start the application:
npm start
The application will start listening on port 5000 by default. You can customize the port by modifying the port variable in the code.
To capture a screenshot of a web page, make a GET request to the root endpoint ("/") with the url query parameter specifying the URL of the web page you want to capture.
Example:
curl "http://localhost:5000/?url=https://example.com"
The captured screenshot will be returned as an image response.
You can also use predefined routes to capture screenshots of specific web pages:
- /soil: Captures a screenshot of a soil data visualization page.
- /weather: Captures a screenshot of a weather data visualization page.
Example:
curl "http://localhost:5000/soil"
- If the url query parameter is missing in a request to the root endpoint ("/"), a 400 Bad Request response will be returned.
- If an error occurs during screenshot capture, a 500 Internal Server Error response will be returned.
- You can customize the Puppeteer launch options, such as disabling the sandbox, by modifying the puppeteerLaunchOptions object in the code.
- Adjust the viewport size and other capture settings within the captureScreenshot function.
Contributions to this project are welcome. Feel free to fork the repository, make changes, and submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.