added EXTERNAL_PORT env variable

This commit is contained in:
Sami Salkosuo 2020-04-22 12:13:00 +03:00
parent 8e027c9c7d
commit 8be6bc6a10
4 changed files with 10 additions and 2 deletions

View File

@ -1,3 +1,7 @@
=== 0.3
* Added EXTERNAL_PORT env variable.
=== 0.2
* Added extract images and audio endpoints.

View File

@ -56,6 +56,8 @@ FFMPEG API is provided as Docker image for easy consumption.
** `docker run -it --rm -p 3000:3000 -e FILE_SIZE_LIMIT_BYTES=1048576 kazhar/ffmpeg-api`
* All uploaded and converted files are deleted when they've been downloaded. Use environment variable _KEEP_ALL_FILES_ to keep all files inside the container /tmp-directory:
** `docker run -it --rm -p 3000:3000 -e KEEP_ALL_FILES=true kazhar/ffmpeg-api`
* When running on Docker/Kubernetes, port binding can be different than default 3000. Use _EXTERNAL_PORT_ to set up external port in returned URLs in extracted images JSON:
** `docker run -it --rm -p 3001:3000 -e EXTERNAL_PORT=3001 kazhar/ffmpeg-api`
== Usage

View File

@ -2,4 +2,5 @@
exports.fileSizeLimit = parseInt(process.env.FILE_SIZE_LIMIT_BYTES || "536870912"); //536870912 = 512MB
exports.defaultFFMPEGProcessPriority=10;
exports.serverPort = 3000;//port to listen, NOTE: if using Docker/Kubernetes this port may not be the one clients are using
exports.externalPort = process.env.EXTERNAL_PORT;//external port that server listens, set this if using for example docker container and binding port is other than 3000
exports.keepAllFiles = process.env.KEEP_ALL_FILES || "false"; //if true, do not delete any uploaded/generated files

View File

@ -176,15 +176,16 @@ function extract(req,res,next) {
logger.debug(`output files in /tmp`);
var responseJson = {};
let externalPort = constants.externalPort || constants.serverPort;
responseJson["totalfiles"] = files.length;
responseJson["description"] = `Extracted image files and URLs to download them. By default, downloading image also deletes the image from server. Note that port ${constants.serverPort} in the URL may not be the same as the real port, especially if server is running on Docker/Kubernetes.`;
responseJson["description"] = `Extracted image files and URLs to download them. By default, downloading image also deletes the image from server. Note that port ${externalPort} in the URL may not be the same as the real port, especially if server is running on Docker/Kubernetes.`;
var filesArray=[];
for (var i=0; i < files.length; i++) {
var file = files[i];
logger.debug("file: " + file);
var fileJson={};
fileJson["name"] = file;
fileJson[`url`] = `${req.protocol}://${req.hostname}:${constants.serverPort}${req.baseUrl}/download/${file}`;
fileJson[`url`] = `${req.protocol}://${req.hostname}:${externalPort}${req.baseUrl}/download/${file}`;
filesArray.push(fileJson);
}
responseJson["files"] = filesArray;