kylejohnson / Patiobar

A web frontend for pianobar, which is a CLI frontend for Pandora.
MIT License
62 stars 22 forks source link

converting to https (feature request not "real issue") #14

Closed hatcreek68 closed 6 years ago

hatcreek68 commented 6 years ago

I changed the header to the code below in patiobar/index.js to try and connect via https - and i can get to the new HTTPS site, but it breaks the link to pianobar data and controls.

var express = require('express');
var app = require('express')();
var io = require('socket.io')(server);
var fs = require('fs');

var options = {
   key  : fs.readFileSync('/home/pi/selfsign.key'),
   cert : fs.readFileSync('/home/pi/selfsign.crt')
};

var server = require('https').createServer(options,app);

var fifo = process.env.PIANOBAR_FIFO || 'ctl';
var listenPort = process.env.PATIOBAR_PORT || 3000;

server.listen(listenPort);

// Routing

i get this, w/ dead buttons, no data: image

I was trying to merge this example header w/ the patiobar/index.js header. [https example]((https://www.sitepoint.com/how-to-use-ssltls-with-node-js/)

var fs = require('fs');
var https = require('https');
var app = require('express')();
var options = {
   key  : fs.readFileSync('server.key'),
   cert : fs.readFileSync('server.crt')
};

app.get('/', function (req, res) {
   res.send('Hello World!');
});

https.createServer(options, app).listen(3000, function () {
   console.log('Started!');
});
kylejohnson commented 6 years ago

By far the easiest option is going to be to reverse proxy node with something like Nginx.

apt-get install nginx Then edit /etc/nginx/sites-enabled/default with something similar to the following:

server {
        listen 80;
        listen 443 ssl http2;
        server_name  patiobar.yourdomain.com;
        access_log  /var/log/nginx/patiobar.access.log;
        ssl_certificate /etc/letsencrypt/live/patiobar/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/patiobar/privkey.pem;
        root /home/pi/Patibar;

        location / {
                proxy_pass http://localhost:3000;
        }

        location /.well-known {
                allow all;
        }
}

Then install letsencrypt and make sure the above ssl_certificate* lines match where letsencrypt put your certificates, and finally restart nginx service nginx restart

hatcreek68 commented 6 years ago

thanks for the tip!

hatcreek68 commented 6 years ago

Just confirming nginx worked great. Thanks again.