August 2017
Intermediate to advanced
278 pages
8h 53m
English
To create our microservice, we're going to create a location block directive with the following:
location /getmxrecords {
default_type 'application/json';
content_by_lua_block {
local cjson = require "cjson.safe"
local resolver = require "resty.dns.resolver"
local r, err = resolver:new{
nameservers = {"8.8.8.8"}
}
if not r then
ngx.say(cjson.encode({result="failed", message="Failed to initiate the resolver. Reason: "..err}))
return
end
local domain = ngx.var.arg_domain
if not domain or not string.match(domain, "[%w]*[%.]?[%w]*") then
ngx.say(cjson.encode({result="failed", message="Invalid domain entered"})) return end local result, err = r:query(domain, { qtype = r.TYPE_MX }) if not result then ngx.say(cjson.encode({result="failed", ...Read now
Unlock full access