payload: {"action":"created","issue":{"url":"https://api.github.com/repos/StackExchange/dnscontrol/issues/474","repository_url":"https://api.github.com/repos/StackExchange/dnscontrol","labels_url":"https://api.github.com/repos/StackExchange/dnscontrol/issues/474/labels{/name}","comments_url":"https://api.github.com/repos/StackExchange/dnscontrol/issues/474/comments","events_url":"https://api.github.com/repos/StackExchange/dnscontrol/issues/474/events","html_url":"https://github.com/StackExchange/dnscontrol/pull/474","id":445234780,"node_id":"MDExOlB1bGxSZXF1ZXN0Mjc5NzI4Nzk3","number":474,"title":"Adds json loading support to require","user":{"login":"ozkar99","id":4227887,"node_id":"MDQ6VXNlcjQyMjc4ODc=","avatar_url":"https://avatars1.githubusercontent.com/u/4227887?v=4","gravatar_id":"","url":"https://api.github.com/users/ozkar99","html_url":"https://github.com/ozkar99","followers_url":"https://api.github.com/users/ozkar99/followers","following_url":"https://api.github.com/users/ozkar99/following{/other_user}","gists_url":"https://api.github.com/users/ozkar99/gists{/gist_id}","starred_url":"https://api.github.com/users/ozkar99/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ozkar99/subscriptions","organizations_url":"https://api.github.com/users/ozkar99/orgs","repos_url":"https://api.github.com/users/ozkar99/repos","events_url":"https://api.github.com/users/ozkar99/events{/privacy}","received_events_url":"https://api.github.com/users/ozkar99/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-05-17T02:20:02Z","updated_at":"2019-05-18T15:14:34Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/StackExchange/dnscontrol/pulls/474","html_url":"https://github.com/StackExchange/dnscontrol/pull/474","diff_url":"https://github.com/StackExchange/dnscontrol/pull/474.diff","patch_url":"https://github.com/StackExchange/dnscontrol/pull/474.patch"},"body":"This commits adds support for require to load arbitrary \"json\" files.\r\n\r\nThis is useful for moving configuration/variables to their own file, and having them as `json` makes it much easier to manipulate using existing tooling.\r\n\r\nRationale:\r\n-------------------------\r\n\r\nIn our use cases we have come regularly to the (anti) pattern of importing data files into variables like:\r\n\r\ndomains.js:\r\n```json\r\nENABLED_DOMAINS = [\r\n  \"domain1.com\",\r\n  \"domain2.com\",\r\n]\r\n```\r\n\r\nAnd then later on `dnsconfig.js` issuing a `require './domains.js'` and using the `ENABLED_DOMAINS` variable, for varied use cases (like looping through it to configure ips).\r\n\r\nHowever, the `js` format becomes a problem if you want to manipulate the `domains` file, as this means, that you have to written custom parsers taking into account the variable declaration part.\r\n\r\nIf we add `json` loading, we can use any existing tooling to: read, write or modify these files much more easily.\r\n\r\n\r\nSample \"check\" Output:\r\n-----------------------------\r\n\r\nip-map.json:\r\n```json\r\n{\r\n  \"192.168.1.1\": \"host1\",\r\n  \"192.168.1.2\": \"host2\",\r\n  \"192.168.1.3\": \"host3\",\r\n  \"192.168.1.4\": \"host4\",\r\n  \"192.168.1.5\": \"host5\"\r\n}\r\n```\r\n\r\n\r\ndnsconfig.js:\r\n```javascript\r\nvar IP_MAP = require('./ip-map.json')\r\n\r\nfunction reverseIPMap() {\r\n\tvar ret = {};\r\n\tfor (var ip in IP_MAP) {\r\n\t\tret[IP_MAP[ip]] = ip;\r\n\t}\r\n\treturn ret;\r\n}\r\n\r\nvar HOSTNAME_MAP = reverseIPMap();\r\n\r\nconsole.log(HOSTNAME_MAP['host3'])\r\n```\r\n\r\ndnscontrol check output:\r\n```\r\n192.168.1.3\r\nNo errors.\r\n```"},"comment":{"url":"https://api.github.com/repos/StackExchange/dnscontrol/issues/comments/493684443","html_url":"https://github.com/StackExchange/dnscontrol/pull/474#issuecomment-493684443","issue_url":"https://api.github.com/repos/StackExchange/dnscontrol/issues/474","id":493684443,"node_id":"MDEyOklzc3VlQ29tbWVudDQ5MzY4NDQ0Mw==","user":{"login":"tlimoncelli","id":6293917,"node_id":"MDQ6VXNlcjYyOTM5MTc=","avatar_url":"https://avatars3.githubusercontent.com/u/6293917?v=4","gravatar_id":"","url":"https://api.github.com/users/tlimoncelli","html_url":"https://github.com/tlimoncelli","followers_url":"https://api.github.com/users/tlimoncelli/followers","following_url":"https://api.github.com/users/tlimoncelli/following{/other_user}","gists_url":"https://api.github.com/users/tlimoncelli/gists{/gist_id}","starred_url":"https://api.github.com/users/tlimoncelli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tlimoncelli/subscriptions","organizations_url":"https://api.github.com/users/tlimoncelli/orgs","repos_url":"https://api.github.com/users/tlimoncelli/repos","events_url":"https://api.github.com/users/tlimoncelli/events{/privacy}","received_events_url":"https://api.github.com/users/tlimoncelli/received_events","type":"User","site_admin":false},"created_at":"2019-05-18T15:14:34Z","updated_at":"2019-05-18T15:14:34Z","author_association":"CONTRIBUTOR","body":"Very cool!  I can see how useful this will be.\r\n\r\nCan you update the docs?"}}
other: {"actor":{"display_login":"tlimoncelli"}}