{"action":"created","comment":{"url":"https://api.github.com/repos/letsencrypt/node-acme/pulls/comments/25155365","id":25155365,"diff_hunk":"@@ -0,0 +1,111 @@\n+//This example will run getMeACertificate once, each time you deploy it on a new server.\n+//It will save the certificate under /etc/letsencrypt on that server, and use\n+//it from there for the rest of the deployed server's lifetime.\n+\n+var fs = require('fs'),\n+    mkdirp = require('mkdirp'),\n+    pki = require('node-forge').pki;\n+    acme = require('node-acme'),\n+    https = require('https'),\n+    express = require('express');\n+\n+var acmeServer = 'www.letsencrypt-demo.org';\n+var certificatesFolder = '/etc/letsencrypt/';\n+\n+function getHttpsOptionsFromDisk(domain, callback) {\n+  fs.readFile(certificatesFolder + domain + '/cert.pem', function(err1, certData) {\n+    if (err1) {\n+      callback(err1);\n+    } else {\n+      fs.readFile(certificatesFolder + domain + '/key.pem', function(err2, keyData) {\n+        if (err1) {\n+          callback(err1);\n+        } else {\n+          callback(null, {\n+            key: keyData,\n+            cert: certData\n+          });\n+        }\n+      });\n+    }\n+  });\n+}\n+\n+function saveHttpsOptionsToDisk(domain, options, callback) {\n+  mkdirp(certificatesFolder + domain, function(err1) {\n+    if (err1) {\n+      callback(err1);\n+    } else {\n+      fs.writeFile(certificatesFolder + domain + '/key.pem', options.key, function (err2) {\n+        if (err2) {\n+          callback(err2);\n+        } else {\n+          fs.writeFile(certificatesFolder + domain + '/cert.pem', options.cert, function (err3) {\n+            callback(err3);\n+          });\n+        }\n+      });\n+    }\n+  });\n+}\n+\n+function acmeResultToHttpsOptions(result) {\n+  return {\n+    key: acme.privateKeyToPem(result.subjectKeyPair.privateKey),\n+    cert: acme.certificateToPem(result.certificate)\n+  };\n+}\n+\n+function getHttpsOptions(domain, callback) {\n+  fs.exists(certificatesFolder + domain, function(exists) {\n+    if (exists) {\n+      console.log('Certificate for ' + domain + ' already present in ' + certificatesFolder + domain + ', using that.');\n+      getHttpsOptionsFromDisk(domain, callback);\n+    } else {\n+      console.log('No certificate for ' + domain + ' yet on this server, getting one.');\n+      acme.getMeACertificate(acmeServer, domain, function(result) {","path":"examples/onfirstrun.js","position":66,"original_position":66,"commit_id":"075958e20bb1ce273164a6669751acfde300a2b3","original_commit_id":"075958e20bb1ce273164a6669751acfde300a2b3","user":{"login":"michielbdejong","id":408412,"avatar_url":"https://avatars.githubusercontent.com/u/408412?v=3","gravatar_id":"","url":"https://api.github.com/users/michielbdejong","html_url":"https://github.com/michielbdejong","followers_url":"https://api.github.com/users/michielbdejong/followers","following_url":"https://api.github.com/users/michielbdejong/following{/other_user}","gists_url":"https://api.github.com/users/michielbdejong/gists{/gist_id}","starred_url":"https://api.github.com/users/michielbdejong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michielbdejong/subscriptions","organizations_url":"https://api.github.com/users/michielbdejong/orgs","repos_url":"https://api.github.com/users/michielbdejong/repos","events_url":"https://api.github.com/users/michielbdejong/events{/privacy}","received_events_url":"https://api.github.com/users/michielbdejong/received_events","type":"User","site_admin":false},"body":"This assumes the corrected version of `getMeACertificate` from #24, will fail when running  against the current master or npm-published version.","created_at":"2015-02-23T10:50:39Z","updated_at":"2015-02-23T10:50:39Z","html_url":"https://github.com/letsencrypt/node-acme/pull/30#discussion_r25155365","pull_request_url":"https://api.github.com/repos/letsencrypt/node-acme/pulls/30","_links":{"self":{"href":"https://api.github.com/repos/letsencrypt/node-acme/pulls/comments/25155365"},"html":{"href":"https://github.com/letsencrypt/node-acme/pull/30#discussion_r25155365"},"pull_request":{"href":"https://api.github.com/repos/letsencrypt/node-acme/pulls/30"}}},"pull_request":{"url":"https://api.github.com/repos/letsencrypt/node-acme/pulls/30","id":29799303,"html_url":"https://github.com/letsencrypt/node-acme/pull/30","diff_url":"https://github.com/letsencrypt/node-acme/pull/30.diff","patch_url":"https://github.com/letsencrypt/node-acme/pull/30.patch","issue_url":"https://api.github.com/repos/letsencrypt/node-acme/issues/30","number":30,"state":"open","locked":false,"title":"add examples/onfirstrun.js","user":{"login":"michielbdejong","id":408412,"avatar_url":"https://avatars.githubusercontent.com/u/408412?v=3","gravatar_id":"","url":"https://api.github.com/users/michielbdejong","html_url":"https://github.com/michielbdejong","followers_url":"https://api.github.com/users/michielbdejong/followers","following_url":"https://api.github.com/users/michielbdejong/following{/other_user}","gists_url":"https://api.github.com/users/michielbdejong/gists{/gist_id}","starred_url":"https://api.github.com/users/michielbdejong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michielbdejong/subscriptions","organizations_url":"https://api.github.com/users/michielbdejong/orgs","repos_url":"https://api.github.com/users/michielbdejong/repos","events_url":"https://api.github.com/users/michielbdejong/events{/privacy}","received_events_url":"https://api.github.com/users/michielbdejong/received_events","type":"User","site_admin":false},"body":"Might be useful to others, especially the `acmeResultToHttpsOptions` function.","created_at":"2015-02-23T10:47:50Z","updated_at":"2015-02-23T10:50:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"08b48b54cf0ac70eb30a1f789d5866d39cbf88f4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/letsencrypt/node-acme/pulls/30/commits","review_comments_url":"https://api.github.com/repos/letsencrypt/node-acme/pulls/30/comments","review_comment_url":"https://api.github.com/repos/letsencrypt/node-acme/pulls/comments{/number}","comments_url":"https://api.github.com/repos/letsencrypt/node-acme/issues/30/comments","statuses_url":"https://api.github.com/repos/letsencrypt/node-acme/statuses/075958e20bb1ce273164a6669751acfde300a2b3","head":{"label":"michielbdejong:onfirstrun","ref":"onfirstrun","sha":"075958e20bb1ce273164a6669751acfde300a2b3","user":{"login":"michielbdejong","id":408412,"avatar_url":"https://avatars.githubusercontent.com/u/408412?v=3","gravatar_id":"","url":"https://api.github.com/users/michielbdejong","html_url":"https://github.com/michielbdejong","followers_url":"https://api.github.com/users/michielbdejong/followers","following_url":"https://api.github.com/users/michielbdejong/following{/other_user}","gists_url":"https://api.github.com/users/michielbdejong/gists{/gist_id}","starred_url":"https://api.github.com/users/michielbdejong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michielbdejong/subscriptions","organizations_url":"https://api.github.com/users/michielbdejong/orgs","repos_url":"https://api.github.com/users/michielbdejong/repos","events_url":"https://api.github.com/users/michielbdejong/events{/privacy}","received_events_url":"https://api.github.com/users/michielbdejong/received_events","type":"User","site_admin":false},"repo":{"id":31127435,"name":"node-acme","full_name":"michielbdejong/node-acme","owner":{"login":"michielbdejong","id":408412,"avatar_url":"https://avatars.githubusercontent.com/u/408412?v=3","gravatar_id":"","url":"https://api.github.com/users/michielbdejong","html_url":"https://github.com/michielbdejong","followers_url":"https://api.github.com/users/michielbdejong/followers","following_url":"https://api.github.com/users/michielbdejong/following{/other_user}","gists_url":"https://api.github.com/users/michielbdejong/gists{/gist_id}","starred_url":"https://api.github.com/users/michielbdejong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michielbdejong/subscriptions","organizations_url":"https://api.github.com/users/michielbdejong/orgs","repos_url":"https://api.github.com/users/michielbdejong/repos","events_url":"https://api.github.com/users/michielbdejong/events{/privacy}","received_events_url":"https://api.github.com/users/michielbdejong/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/michielbdejong/node-acme","description":"","fork":true,"url":"https://api.github.com/repos/michielbdejong/node-acme","forks_url":"https://api.github.com/repos/michielbdejong/node-acme/forks","keys_url":"https://api.github.com/repos/michielbdejong/node-acme/keys{/key_id}","collaborators_url":"https://api.github.com/repos/michielbdejong/node-acme/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/michielbdejong/node-acme/teams","hooks_url":"https://api.github.com/repos/michielbdejong/node-acme/hooks","issue_events_url":"https://api.github.com/repos/michielbdejong/node-acme/issues/events{/number}","events_url":"https://api.github.com/repos/michielbdejong/node-acme/events","assignees_url":"https://api.github.com/repos/michielbdejong/node-acme/assignees{/user}","branches_url":"https://api.github.com/repos/michielbdejong/node-acme/branches{/branch}","tags_url":"https://api.github.com/repos/michielbdejong/node-acme/tags","blobs_url":"https://api.github.com/repos/michielbdejong/node-acme/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/michielbdejong/node-acme/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/michielbdejong/node-acme/git/refs{/sha}","trees_url":"https://api.github.com/repos/michielbdejong/node-acme/git/trees{/sha}","statuses_url":"https://api.github.com/repos/michielbdejong/node-acme/statuses/{sha}","languages_url":"https://api.github.com/repos/michielbdejong/node-acme/languages","stargazers_url":"https://api.github.com/repos/michielbdejong/node-acme/stargazers","contributors_url":"https://api.github.com/repos/michielbdejong/node-acme/contributors","subscribers_url":"https://api.github.com/repos/michielbdejong/node-acme/subscribers","subscription_url":"https://api.github.com/repos/michielbdejong/node-acme/subscription","commits_url":"https://api.github.com/repos/michielbdejong/node-acme/commits{/sha}","git_commits_url":"https://api.github.com/repos/michielbdejong/node-acme/git/commits{/sha}","comments_url":"https://api.github.com/repos/michielbdejong/node-acme/comments{/number}","issue_comment_url":"https://api.github.com/repos/michielbdejong/node-acme/issues/comments{/number}","contents_url":"https://api.github.com/repos/michielbdejong/node-acme/contents/{+path}","compare_url":"https://api.github.com/repos/michielbdejong/node-acme/compare/{base}...{head}","merges_url":"https://api.github.com/repos/michielbdejong/node-acme/merges","archive_url":"https://api.github.com/repos/michielbdejong/node-acme/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/michielbdejong/node-acme/downloads","issues_url":"https://api.github.com/repos/michielbdejong/node-acme/issues{/number}","pulls_url":"https://api.github.com/repos/michielbdejong/node-acme/pulls{/number}","milestones_url":"https://api.github.com/repos/michielbdejong/node-acme/milestones{/number}","notifications_url":"https://api.github.com/repos/michielbdejong/node-acme/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/michielbdejong/node-acme/labels{/name}","releases_url":"https://api.github.com/repos/michielbdejong/node-acme/releases{/id}","created_at":"2015-02-21T14:09:25Z","updated_at":"2015-02-21T14:09:27Z","pushed_at":"2015-02-23T10:45:55Z","git_url":"git://github.com/michielbdejong/node-acme.git","ssh_url":"git@github.com:michielbdejong/node-acme.git","clone_url":"https://github.com/michielbdejong/node-acme.git","svn_url":"https://github.com/michielbdejong/node-acme","homepage":null,"size":283,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"letsencrypt:master","ref":"master","sha":"c5392cd67e60e5420087ca697d8051e1c1670c0f","user":{"login":"letsencrypt","id":9289019,"avatar_url":"https://avatars.githubusercontent.com/u/9289019?v=3","gravatar_id":"","url":"https://api.github.com/users/letsencrypt","html_url":"https://github.com/letsencrypt","followers_url":"https://api.github.com/users/letsencrypt/followers","following_url":"https://api.github.com/users/letsencrypt/following{/other_user}","gists_url":"https://api.github.com/users/letsencrypt/gists{/gist_id}","starred_url":"https://api.github.com/users/letsencrypt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/letsencrypt/subscriptions","organizations_url":"https://api.github.com/users/letsencrypt/orgs","repos_url":"https://api.github.com/users/letsencrypt/repos","events_url":"https://api.github.com/users/letsencrypt/events{/privacy}","received_events_url":"https://api.github.com/users/letsencrypt/received_events","type":"Organization","site_admin":false},"repo":{"id":25449714,"name":"node-acme","full_name":"letsencrypt/node-acme","owner":{"login":"letsencrypt","id":9289019,"avatar_url":"https://avatars.githubusercontent.com/u/9289019?v=3","gravatar_id":"","url":"https://api.github.com/users/letsencrypt","html_url":"https://github.com/letsencrypt","followers_url":"https://api.github.com/users/letsencrypt/followers","following_url":"https://api.github.com/users/letsencrypt/following{/other_user}","gists_url":"https://api.github.com/users/letsencrypt/gists{/gist_id}","starred_url":"https://api.github.com/users/letsencrypt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/letsencrypt/subscriptions","organizations_url":"https://api.github.com/users/letsencrypt/orgs","repos_url":"https://api.github.com/users/letsencrypt/repos","events_url":"https://api.github.com/users/letsencrypt/events{/privacy}","received_events_url":"https://api.github.com/users/letsencrypt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/letsencrypt/node-acme","description":"","fork":false,"url":"https://api.github.com/repos/letsencrypt/node-acme","forks_url":"https://api.github.com/repos/letsencrypt/node-acme/forks","keys_url":"https://api.github.com/repos/letsencrypt/node-acme/keys{/key_id}","collaborators_url":"https://api.github.com/repos/letsencrypt/node-acme/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/letsencrypt/node-acme/teams","hooks_url":"https://api.github.com/repos/letsencrypt/node-acme/hooks","issue_events_url":"https://api.github.com/repos/letsencrypt/node-acme/issues/events{/number}","events_url":"https://api.github.com/repos/letsencrypt/node-acme/events","assignees_url":"https://api.github.com/repos/letsencrypt/node-acme/assignees{/user}","branches_url":"https://api.github.com/repos/letsencrypt/node-acme/branches{/branch}","tags_url":"https://api.github.com/repos/letsencrypt/node-acme/tags","blobs_url":"https://api.github.com/repos/letsencrypt/node-acme/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/letsencrypt/node-acme/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/letsencrypt/node-acme/git/refs{/sha}","trees_url":"https://api.github.com/repos/letsencrypt/node-acme/git/trees{/sha}","statuses_url":"https://api.github.com/repos/letsencrypt/node-acme/statuses/{sha}","languages_url":"https://api.github.com/repos/letsencrypt/node-acme/languages","stargazers_url":"https://api.github.com/repos/letsencrypt/node-acme/stargazers","contributors_url":"https://api.github.com/repos/letsencrypt/node-acme/contributors","subscribers_url":"https://api.github.com/repos/letsencrypt/node-acme/subscribers","subscription_url":"https://api.github.com/repos/letsencrypt/node-acme/subscription","commits_url":"https://api.github.com/repos/letsencrypt/node-acme/commits{/sha}","git_commits_url":"https://api.github.com/repos/letsencrypt/node-acme/git/commits{/sha}","comments_url":"https://api.github.com/repos/letsencrypt/node-acme/comments{/number}","issue_comment_url":"https://api.github.com/repos/letsencrypt/node-acme/issues/comments{/number}","contents_url":"https://api.github.com/repos/letsencrypt/node-acme/contents/{+path}","compare_url":"https://api.github.com/repos/letsencrypt/node-acme/compare/{base}...{head}","merges_url":"https://api.github.com/repos/letsencrypt/node-acme/merges","archive_url":"https://api.github.com/repos/letsencrypt/node-acme/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/letsencrypt/node-acme/downloads","issues_url":"https://api.github.com/repos/letsencrypt/node-acme/issues{/number}","pulls_url":"https://api.github.com/repos/letsencrypt/node-acme/pulls{/number}","milestones_url":"https://api.github.com/repos/letsencrypt/node-acme/milestones{/number}","notifications_url":"https://api.github.com/repos/letsencrypt/node-acme/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/letsencrypt/node-acme/labels{/name}","releases_url":"https://api.github.com/repos/letsencrypt/node-acme/releases{/id}","created_at":"2014-10-20T03:43:19Z","updated_at":"2015-02-22T13:32:29Z","pushed_at":"2015-02-19T00:40:55Z","git_url":"git://github.com/letsencrypt/node-acme.git","ssh_url":"git@github.com:letsencrypt/node-acme.git","clone_url":"https://github.com/letsencrypt/node-acme.git","svn_url":"https://github.com/letsencrypt/node-acme","homepage":null,"size":283,"stargazers_count":219,"watchers_count":219,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":14,"mirror_url":null,"open_issues_count":19,"forks":14,"open_issues":19,"watchers":219,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/letsencrypt/node-acme/pulls/30"},"html":{"href":"https://github.com/letsencrypt/node-acme/pull/30"},"issue":{"href":"https://api.github.com/repos/letsencrypt/node-acme/issues/30"},"comments":{"href":"https://api.github.com/repos/letsencrypt/node-acme/issues/30/comments"},"review_comments":{"href":"https://api.github.com/repos/letsencrypt/node-acme/pulls/30/comments"},"review_comment":{"href":"https://api.github.com/repos/letsencrypt/node-acme/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/letsencrypt/node-acme/pulls/30/commits"},"statuses":{"href":"https://api.github.com/repos/letsencrypt/node-acme/statuses/075958e20bb1ce273164a6669751acfde300a2b3"}}}}