CORS Server Documentation

CORS Server Documentation

External API Endpoints

These endpoints proxy requests to external APIs with CORS headers and authentication.

GET /alienstore/collect-reviews

Collects reviews from Judge.me API for Alien Store

URL: https://judge.me/api/v1/reviews
Parameters: api_token, shop_domain, rating

GET /dispotrading/company-data/:cui

Fetches company data from InfoCUI API

URL: https://infocui.ro/system/api/data
Parameters: key, cui

GET /dispotrading/company-finance/:cui/:year

Fetches company financial data from InfoCUI API

URL: https://infocui.ro/system/api/finance
Parameters: key, cui, year

POST /peterdobias/klaviyo-subscribe-canada

Subscribes users to Klaviyo Canada list

URL: https://a.klaviyo.com/api/v2/list/UgFDvU/subscribe
Parameters: api_key

POST /peterdobias/klaviyo-subscribe-usa

Subscribes users to Klaviyo USA list

URL: https://a.klaviyo.com/api/v2/list/T9yCTT/subscribe
Parameters: api_key

Internal API Endpoints

These endpoints handle internal operations with MongoDB and other services.

Fyne Jewellery Endpoints

GET /fyne-jewellery/exchange-rates

Retrieves current exchange rates

Collection: exchange_rates
Operation: findOne

GET /fyne-jewellery/wishlist/get

Retrieves wishlist data

Collection: wishlist
Operation: findOne

POST /fyne-jewellery/wishlist/update

Updates wishlist data

Collection: wishlist
Operation: updateOne
Body: JSON with filter and update data

POST /fyne-jewellery/wishlist/create

Creates new wishlist entry

Collection: wishlist
Operation: insertOne
Body: JSON with document data

How to Add New Endpoints

Adding External API Endpoints

To add a new external API endpoint:

1. Open lib/api-endpoints.js
2. Add a new entry to the module.exports object:

'/your-endpoint/path': {
    url: 'https://api.example.com/endpoint',
    params: {
        api_key: 'YOUR_ENV_VAR_NAME',
        // other parameters
    },
},

3. Add the corresponding environment variable to your .env file

Adding Internal API Endpoints

To add new internal endpoints:

1. Create a new file in lib/ (e.g., your-project-endpoints.js)
2. Create a class that follows the pattern:

class YourProjectEndpoints {
    constructor() {
        this.endpoints = {
            '/your-project/endpoint': {
                handler: 'findOne', // or 'insertOne', 'updateOne', etc.
                collection: 'your_collection',
            },
        };
    }

    async handleRequest(req, res) {
        // Implementation similar to FyneJewelleryEndpoints
    }

    async testConnection() {
        // Test your connection
    }
}

3. Add the new router to lib/internal-endpoints-manager.js:

this.routers = [
    new FyneJewelleryEndpoints(),
    new YourProjectEndpoints(), // Add your new router
];

Environment Variables

Required environment variables:

DOCUMENTATION_PASSWORD=your_secure_password
MONGODB_URI=your_mongodb_connection_string
ALIENSTORE_JUDGEME_API_TOKEN=your_token
DISPOTRADING_INFOCUI_API_KEY=your_key
PD_KLAVIYO_API_CANADA=your_key
PD_KLAVIYO_API_USA=your_key