-
Notifications
You must be signed in to change notification settings - Fork 582
How to put a password on peerflix server using basic auth
DarkVenusNet edited this page Jan 9, 2018
·
11 revisions
This is a guide for putting a password on peerflix-server without using squit or Nginx.
Tested on Ubuntu 16.04
You need to install basic-auth
and nano
npm install basic-auth
apt-get -y install nano
- if you have started peerflix-server with the command
peerflix-server
then clickCtrl
+C
or
- if you are running peerflix-server with forever
forever stop /usr/bin/peerflix-server
Open the file index.js
with nano
nano /usr/lib/node_modules/peerflix-server/server/index.js
and replace
- api.use(function (req, res, next) {
- res.header('Access-Control-Allow-Origin', '*');
- res.header('Access-Control-Allow-Methods', 'OPTIONS, POST, GET, PUT, DELETE');
- res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
to
- var basicAuth = require('basic-auth');
- var dvnuser = 'your_user';
- var dvnpass = 'your_pass';
- api.use(function (req, res, next) {
- function unauthorized(res) {
- res.set('WWW-Authenticate', 'Basic realm=Authorization Required');
- eturn res.send(401);
- };
- var user = basicAuth(req);
- if (!user || !user.name || !user.pass) {
- return unauthorized(res);
- };
- if (user.name === dvnuser && user.pass === dvnpass) {
- res.header('Access-Control-Allow-Origin', '*');
- res.header('Access-Control-Allow-Methods', 'OPTIONS, POST, GET, PUT, DELETE');
- res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
- return next();
- } else {
- return unauthorized(res);
- };
P.S.: replace your_ user
and your_pass
with your desired username and password
Click Ctrl
+ X
then click two times enter
to exit
- You can start peerflix-server normally with
peerflix-server
command
or
- You can start peerflix-server using forever
forever start $(which peerflix-server)