greenlock.js/examples/ursa.js

55 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2015-12-15 11:44:09 +00:00
'use strict';
var LE = require('../');
var config = require('./config-minimal');
// Note: you should make this special dir in your product and leave it empty
config.le.webrootPath = __dirname + '/../tests/acme-challenge';
config.le.server = LE.stagingServer;
//
// Manual Registration
//
2015-12-16 09:34:39 +00:00
var le = LE.create(config.le);
2015-12-15 13:28:52 +00:00
le.backend.registerAsync({
2015-12-15 11:44:09 +00:00
agreeTos: true
2015-12-15 13:28:52 +00:00
, domains: ['example.com'] // CHANGE TO YOUR DOMAIN
, email: 'user@example.com' // CHANGE TO YOUR EMAIL
}, function (err, body) {
2015-12-15 11:44:09 +00:00
if (err) {
console.error('[Error]: node-letsencrypt/examples/ursa');
console.error(err.stack);
} else {
2015-12-15 13:28:52 +00:00
console.log('success', body);
2015-12-15 11:44:09 +00:00
}
plainServer.close();
tlsServer.close();
2015-12-15 13:28:52 +00:00
}).then(function () {}, function (err) {
console.error(err.stack);
2015-12-15 11:44:09 +00:00
});
//
// Express App
//
var app = require('express')();
app.use('/', le.middleware());
//
// HTTP & HTTPS servers
// (required for domain validation)
//
var plainServer = require('http').createServer(app).listen(config.plainPort, function () {
console.log('Listening http', this.address());
});
var tlsServer = require('https').createServer({
key: config.tlsKey
, cert: config.tlsCert
, SNICallback: le.sniCallback
}, app).listen(config.tlsPort, function () {
console.log('Listening http', this.address());
});