I have a project setup with a node.js api and a minio service with docker compose:
app:
image: node
# ...
minio:
image: minio/minio
volumes:
- ./data:/data
ports:
- '9000:9000'
- '9001:9001'
command: server --console-address ":9001" /data
In my node script I run the following code:
import * as Minio from 'minio';
const minioClient = new Minio.Client({
endPoint: 'minio',
port: 9000,
useSSL: false,
accessKey: 'access',
secretKey: 'secret',
});
minioClient.presignedUrl(
'GET',
'my-bucket',
'test.txt',
function (err, presignedUrl) {
if (err) {
return console.error(err);
}
console.log(presignedUrl);
}
);
The result is a url like this:
http://minio:9000/files-c000000000000000000000000/test.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=u7gk0nycOepyDAWV%2F20230314%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230314T131440Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=315c9184a40009ff5af0815e597214b6422650e240d186979295c5188cbb2885
In my dev environment I need the url to use localhost instead of minio like this:\
http://localhost:9000/files-c000000000000000000000000/test1678799680428.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=u7gk0nycOepyDAWV%2F20230314%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230314T131440Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=315c9184a40009ff5af0815e597214b6422650e240d186979295c5188cbb2885
What I have tried so far (and did not work):
- Simple string replace for the hostname => The hash is only valid for the hostname the url is created with
- Set the endPoint in Minio.Client to localhost. => The api could not connect to minIO any more.
- Set environment variables MINIO_SERVER_URL, MINIO_BROWSER_REDIRECT_URL and MINIO_DOMAIN with localhost => Same Error
Workaround
A Simple workaround is to manually redirect the docker service name minio to 127.0.0.1. But I am searching for a solution without this workaround.