-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlets-encrypt.js
29 lines (23 loc) · 964 Bytes
/
lets-encrypt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { Meteor } from 'meteor/meteor';
import { WebApp } from 'meteor/webapp';
const fs = require('fs');
const Url = require('url');
WebApp.connectHandlers.use("/.well-known/acme-challenge/", function(req, res, next) {
const challengesDir = Meteor.settings.letsEncryptChallengesDir || Meteor.settings.private.letsEncryptChallengesDir;
let challengeFilename = Url.parse(req.url).pathname;
// strip out characters that aren't usually in tokens generated by the Let's Encrypt certbot
challengeFilename = challengeFilename.replace(/[^a-zA-Z0-9\-_]+/g, '');
let challengeResponse = '';
try{
challengeResponse = fs.readFileSync(challengesDir + challengeFilename, 'utf8');
}catch(error){
console.log('Error opening Let\'s Encrypt challenge file:');
console.log(error);
res.writeHead(404);
let page = 'Could not find that challenge file.';
res.end(page);
return;
}
res.writeHead(200);
res.end(challengeResponse);
});