This is a proxy server designed specifically to securely forward translation requests to the DeepLX API. It acts as an intermediary to protect your DeepLX API key, preventing its exposure in client-side code.
The server is configured with a strict CORS policy, allowing requests only from specified origins.
- The server exposes a single
POST /translateendpoint. - A client application sends a request to this endpoint with the text to be translated, the source language, and the target language.
- The proxy server retrieves the secret
DEEPLX_API_KEYfrom its environment variables. - It then forwards the translation request, including the secret key, to the
https://api.deeplx.org/translateAPI. - Finally, it returns the response from the DeepLX API directly to the client.
You can deploy your own instance to Vercel with one click:
Forwards a translation request to the DeepLX API.
Request Body:
{
"text": "Hello, world!",
"source_lang": "EN",
"target_lang": "ZH"
}Success Response:
The JSON response from the DeepLX API.
Error Response:
If the request fails, the server-side API key is not configured, or input validation fails, it returns a 400 or 500 status code with a JSON body:
{
"error": "Error message",
"details": "Optional additional details or validation errors"
}To function correctly, the server requires the following environment variables. You can set these variables in your deployment environment, or by creating a .env file in the project root:
DEEPLX_API_KEY: Your secret DeepLX API key.DEEPLX_API_KEY=your_secret_deeplx_api_keyALLOWED_ORIGINS: A comma-separated list of allowed CORS origins (e.g.,https://example.com,http://localhost:8080).ALLOWED_ORIGINS=https://example.com,http://localhost:3000RATE_LIMIT_MAX: (Optional) The maximum number of requests allowed per IP per 15 minutes. Default is 100 if not set.RATE_LIMIT_MAX=200
-
Install dependencies:
npm install
-
Run the server (make sure to replace
your_api_keyandyour_allowed_originswith your actual values):DEEPLX_API_KEY=your_api_key ALLOWED_ORIGINS=your_allowed_origins npm start
The server will start on port 3000.
This project is configured for easy deployment as a serverless function on Vercel. The vercel.json file handles the necessary build and routing configurations.