I'm trying to ping one of our Rails Microservices (handles emails) from our app, and I'm getting the title error.
Our microservice is running in docker on localhost:3101
, whilst our app is on localhost:3000 on docker also - I've pinged it with postman requests and it's working fine.
I've set our auth token and email service API in our ENV variables like so:-
EMAIL_SERVICE=http://localhost:3101
EMAIL_SERVICE_TOKEN=1234
Here's my EmailService
:-
class EmailService
require 'net/http'
HEADER = { 'Content-Type': 'application/json' }.freeze
ENDPOINTS = {
root: ENV['EMAIL_SERVICE'],
test_email: {
post: {
url: '/api/test_email'
}
}
}
def initialize
@token = ENV['EMAIL_SERVICE_TOKEN']
end
def call_api(section, action, data, method='POST')
address_url = ENDPOINTS[section][action][:url]
uri = URI.parse("#{ENDPOINTS[:root]}#{address_url}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
if method == 'POST'
request = Net::HTTP::Post.new(
uri.request_uri,
HEADER
)
request.body = data.merge({ auth_token: @token }).to_json
else
request = Net::HTTP::Get.new(
uri.request_uri,
HEADER
)
end
http.use_ssl = true
response = http.request(request)
end
end
Any idea what I'm missing?