Skip to content
This repository has been archived by the owner on Jul 30, 2019. It is now read-only.

Commit

Permalink
ttl
Browse files Browse the repository at this point in the history
  • Loading branch information
zen-johnttan committed May 24, 2016
1 parent 40c2c0d commit b1a2572
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app.js
Expand Up @@ -19,7 +19,7 @@ require('colors')
*
* @constructor
*/
var App = function (ProxyDriver, HTTPDriver, DNSDriver, DockerDriver, domain, api_port, proxy_ip, dns_ip, dns_port) {
var App = function (ProxyDriver, HTTPDriver, DNSDriver, DockerDriver, domain, api_port, proxy_ip, dns_ip, dns_port, dns_ttl) {

this.dockerInfos = url.parse(process.env.DOCKER_HOST)
this.proxyDriver = ProxyDriver
Expand All @@ -31,6 +31,7 @@ var App = function (ProxyDriver, HTTPDriver, DNSDriver, DockerDriver, domain, ap
this.proxyIp = proxy_ip
this.dnsIp = dns_ip
this.dnsPort = dns_port
this.dnsTtl = dns_ttl
this.version = require('./package.json').version

// DNS stuff
Expand Down
6 changes: 4 additions & 2 deletions bin/cli.js
Expand Up @@ -28,7 +28,8 @@ var Cli = exports.Cli = function (argv) {
'proxy-ip': '10.254.254.254',
'loopback-ip': '10.254.254.254',
'dns-ip': '127.0.0.1',
'dns-port': 53
'dns-port': 53,
'dns-ttl': 10
})
}

Expand Down Expand Up @@ -83,7 +84,8 @@ Cli.prototype.run = function () {
this.options['api-port'],
this.options['proxy-ip'],
this.options['dns-ip'],
this.options['dns-port']
this.options['dns-port'],
this.options['dns-ttl']
)

// check version
Expand Down
4 changes: 2 additions & 2 deletions lib/dns-server.js
Expand Up @@ -29,14 +29,14 @@ var DNSServer = function (app, driver) {

if (this.entries[requestedDomain]) {
record = new this.driver.ARecord(this.entries[requestedDomain])
query.addAnswer(requestedDomain, record, 10)
query.addAnswer(requestedDomain, record, app.dnsTtl)
this.server.send(query)
} else {
dns.resolve(requestedDomain, 'A', function (err, addresses) {
if (addresses) {
addresses.forEach(function (addr) {
record = new this.driver.ARecord(addr)
query.addAnswer(requestedDomain, record, 10)
query.addAnswer(requestedDomain, record, app.dnsTtl)
}.bind(this))
} else if(err) {
Logger.error("DNS query (A) for domain %s throw an error: " + err, requestedDomain)
Expand Down

0 comments on commit b1a2572

Please sign in to comment.