54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
'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
|
|
//
|
|
var le = LE.create(config.le);
|
|
le.register({
|
|
agreeTos: true
|
|
, domains: [process.argv[3] || 'example.com'] // CHANGE TO YOUR DOMAIN
|
|
, email: process.argv[2] || 'user@example.com' // CHANGE TO YOUR EMAIL
|
|
}, function (err) {
|
|
if (err) {
|
|
console.error('[Error]: node-letsencrypt/examples/standalone');
|
|
console.error(err.stack);
|
|
} else {
|
|
console.log('success');
|
|
}
|
|
|
|
plainServer.close();
|
|
tlsServer.close();
|
|
});
|
|
|
|
|
|
//
|
|
// 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());
|
|
});
|