NodeJS HTTP/HTTPS – Server (with Let’s Encrypt SSL Cert)

Basic HTTP-Server

var fs = require(‚fs‘);
var http = require(‚http‘);
var express = require(‚express‘);
var app = express();

var server = http.createServer(app);
var port = 3000;

server.listen(port, function() {
log(‚listening on *:‘ + port);
});

app.use(express.static(‚public‘));

app.get(‚/‘, (req, res) => {
res.sendFile(‚index.html‘);
});

Extend your Server to HTTPS with Free SSL Cert

var fs = require(‚fs‘);
var https = require(‚https‚);
var express = require(‚express‘);
var app = express();

var options = {
key: fs.readFileSync(‚/etc/letsencrypt/live/hg-system.com/privkey.pem‘),
cert: fs.readFileSync(‚/etc/letsencrypt/live/hg-system.com/fullchain.pem‘)
};

var server = https.createServer(options, app);
var port = 3000;

server.listen(port, function() {
log(‚listening on *:‘ + port);
});

app.use(express.static(‚public‘));

app.get(‚/‘, (req, res) => {
res.sendFile(‚index.html‘);
});

de/ssl-wildcard-example-com/

Schreibe einen Kommentar