Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

rayaimaster/cloudapp

Repository files navigation

Stock Monitor - Instock Detector

A web application that monitors product availability on websites by regularly checking if specific text (indicating out-of-stock status) is present on a webpage.

Features

  • Automated Monitoring: Regularly checks target URLs for stock availability
  • Web Dashboard: Beautiful, responsive web interface to monitor status
  • Real-time Updates: Live status updates and check history
  • Configurable: Easy configuration of target URL, check intervals, and stock indicators
  • Azure Ready: Designed for deployment on Azure Container Apps
  • Logging: Comprehensive logging with Winston
  • Error Handling: Robust error handling with retry logic
  • Security: Helmet.js security headers and CORS configuration

Architecture

  • Backend: Node.js with TypeScript and Express
  • Frontend: Vanilla JavaScript with Tailwind CSS
  • Monitoring: Cheerio for web scraping, Axios for HTTP requests
  • Scheduling: Node-cron for automated checks
  • Deployment: Docker containerization with Azure Container Apps

Quick Start

Prerequisites

  • Node.js 18 or higher
  • npm or yarn
  • Docker (for containerization)
  • Azure CLI (for deployment)

Local Development

  1. Clone and setup:

    cd d:\AIApps\Projects\InstockDetector
    npm install
  2. Configure environment:

    cp .env.example .env

    Edit .env file with your settings:

    TARGET_URL=https://your-target-website.com/product
    CHECK_INTERVAL_MINUTES=5
    OUT_OF_STOCK_TEXT=No products available yet
    
  3. Start development server:

    npm run dev
  4. Open browser: Navigate to http://localhost:3000

Production Build

npm run build
npm start

Configuration

Environment Variables

Variable Description Default
NODE_ENV Environment mode development
PORT Server port 3000
TARGET_URL URL to monitor https://example.com
CHECK_INTERVAL_MINUTES Check frequency in minutes 5
OUT_OF_STOCK_TEXT Text indicating out of stock No products available yet
LOG_LEVEL Logging level info

Runtime Configuration

You can also update configuration through the web interface:

  • Click the "Settings" button in the top right
  • Update Target URL, Check Interval, or Out of Stock Text
  • Changes take effect immediately

API Endpoints

Endpoint Method Description
/health GET Health check
/api/status GET Current stock status and statistics
/api/history GET Recent check history
/api/check POST Perform manual check
/api/config POST Update configuration
/api/scheduler/start POST Start automated monitoring
/api/scheduler/stop POST Stop automated monitoring

Deployment

Azure Container Apps (Recommended)

  1. Build and push container:

    # Build the container
    docker build -t instock-detector .
    # Tag for Azure Container Registry
    docker tag instock-detector <your-acr>.azurecr.io/instock-detector:latest
    # Push to registry
    docker push <your-acr>.azurecr.io/instock-detector:latest
  2. Deploy with Azure Developer CLI:

    azd auth login
    azd init
    azd up
  3. Or deploy with Bicep:

    az deployment group create \
     --resource-group <your-rg> \
     --template-file infra/main.bicep \
     --parameters targetUrl="https://your-site.com" \
     --parameters containerImage="<your-acr>.azurecr.io/instock-detector:latest"

Docker

# Build
docker build -t instock-detector .
# Run
docker run -p 3000:3000 \
 -e TARGET_URL="https://your-site.com" \
 -e CHECK_INTERVAL_MINUTES="5" \
 -e OUT_OF_STOCK_TEXT="No products available yet" \
 instock-detector

Usage Examples

Monitoring E-commerce Sites

  1. Amazon Product Page:

    • URL: https://amazon.com/product-page
    • Out of Stock Text: Currently unavailable
  2. Custom Store:

    • URL: https://store.com/limited-edition-item
    • Out of Stock Text: Sold out
  3. Shopify Store:

    • URL: https://store.shopify.com/products/item
    • Out of Stock Text: Sorry, this item is out of stock

API Usage

// Check stock manually
const response = await fetch('/api/check', { method: 'POST' });
const result = await response.json();
// Update configuration
await fetch('/api/config', {
 method: 'POST',
 headers: { 'Content-Type': 'application/json' },
 body: JSON.stringify({
 targetUrl: 'https://new-site.com',
 checkIntervalMinutes: 10,
 outOfStockText: 'Out of stock'
 })
});

Monitoring and Alerts

The application provides comprehensive logging and monitoring:

  • Health Endpoint: /health for load balancer checks
  • Structured Logging: JSON formatted logs with Winston
  • Azure Integration: Logs automatically sent to Azure Log Analytics
  • Error Tracking: Failed requests and network errors are logged
  • Performance Metrics: Response times and success rates tracked

Security Considerations

  • No Credentials Stored: Uses managed identity for Azure resources
  • Security Headers: Helmet.js provides security headers
  • CORS Configuration: Configurable cross-origin requests
  • Input Validation: All user inputs are validated
  • Rate Limiting: Built-in protection against abuse
  • Container Security: Runs as non-root user

Troubleshooting

Common Issues

  1. Connection Refused:

    • Check if target website blocks automated requests
    • Verify URL is accessible
    • Check firewall settings
  2. False Positives:

    • Adjust the "Out of Stock Text" to be more specific
    • Check if website structure changed
  3. High Memory Usage:

    • Reduce check interval
    • Clear browser cache
    • Monitor for memory leaks

Logs

View logs in different ways:

# Local development
tail -f logs/combined.log
# Docker container
docker logs <container-id>
# Azure Container Apps
az containerapp logs show --name instock-detector --resource-group <rg>

Development

Project Structure

├── src/ # TypeScript source code
│ ├── app.ts # Main Express application
│ ├── stockMonitor.ts # Core monitoring logic
│ ├── scheduler.ts # Cron job scheduling
│ ├── statusManager.ts # Status tracking
│ ├── logger.ts # Winston logging setup
│ └── types.ts # TypeScript type definitions
├── public/ # Static web assets
│ ├── index.html # Web dashboard
│ └── app.js # Frontend JavaScript
├── infra/ # Azure infrastructure as code
│ └── main.bicep # Bicep template
├── Dockerfile # Container configuration
└── azure.yaml # Azure Developer CLI config

Testing

# Run tests
npm test
# Run with coverage
npm run test:coverage
# Lint code
npm run lint

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

MIT License - see LICENSE file for details.

Support

For issues and questions:

  • Create an issue in the repository
  • Check the troubleshooting section
  • Review Azure Container Apps documentation

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

AltStyle によって変換されたページ (->オリジナル) /