implementing options to make PairDrop reachable on localhost only to prevent bypassing the proxy server on production

This commit is contained in:
schlagmichdoch 2023-02-14 02:41:06 +01:00
parent bac272c0f3
commit 58a32d43b3
3 changed files with 43 additions and 22 deletions

View file

@ -15,15 +15,7 @@ npm install
Start the server with: Start the server with:
```bash ```bash
npm start node index.js
```
### Public Run
If you want to run in your public "sharable" IP instead of locally, you can use this command:
```bash
node index.js public
``` ```
or or
```bash ```bash
@ -36,6 +28,29 @@ npm start
<br> <br>
### Environment variables
#### Port
On Unix based systems
```bash
PORT=3010 npm start
```
On Windows
```bash
$env:PORT=3010; npm start
```
> Specify the port PairDrop is running on. (Default: 3000)
### Options / Flags
#### Local Run
```bash
npm start -- --localhost-only
```
> Only allow connections from localhost.
>
> Use this when deploying PairDrop with node.
> This prevents connections to the node server from bypassing the proxy server,
> as you must use a server proxy to point to PairDrop (See [#HTTP-Server](#http-server)).
#### Automatic restart on error #### Automatic restart on error
```bash ```bash
npm start -- --auto-restart npm start -- --auto-restart
@ -73,18 +88,15 @@ npm start -- --include-ws-fallback
npm run start:prod npm run start:prod
``` ```
#### Production (autostart, rate-limit and websocket fallback for VPN) #### Production (autostart, rate-limit, localhost-only and websocket fallback for VPN)
```bash ```bash
npm run start:prod -- --include-ws-fallback npm run start:prod -- --localhost-only --include-ws-fallback
``` ```
> To prevent connections to the node server from bypassing the proxy server you should use "--localhost-only" on production.
## Deployment with Docker ## Deployment with Docker
The easiest way to get PairDrop up and running is by using Docker. The easiest way to get PairDrop up and running is by using Docker.
By default, docker listens on port 3000 for (http and https).
By default, PairDrop is started with auto-start and rate-limit enabled. To run PairDrop with [the options listed above](#public-run) you have to edit the `CMD` command in the Dockerfile accordingly.
### Build the image ### Build the image
```bash ```bash
docker build . -f Dockerfile -t pairdrop docker build . -f Dockerfile -t pairdrop
@ -93,9 +105,14 @@ docker build . -f Dockerfile -t pairdrop
### Run the image ### Run the image
```bash ```bash
docker run -p 3000:3000 -it pairdrop npm run start:prod docker run -p 127.0.0.1:3000:3000 -it pairdrop npm run start:prod
``` ```
> To specify flags replace `npm run start:prod` according to [the documentation above.](#public-run) > By default, PairDrop is started with auto-start and rate-limit enabled.
> By including "127.0.0.1" the docker container is only available on localhost (same as "--localhost-only" when deploying with node).
>
> You must use a server proxy to point to PairDrop (See [#HTTP-Server](#http-server)).
>
> To specify options replace `npm run start:prod` according to [the documentation above.](#options--flags)
## HTTP-Server ## HTTP-Server
When running PairDrop, the `X-Forwarded-For` header has to be set by a proxy. Otherwise, all clients will be mutually visible. When running PairDrop, the `X-Forwarded-For` header has to be set by a proxy. Otherwise, all clients will be mutually visible.

View file

@ -54,7 +54,6 @@ const RateLimit = require('express-rate-limit');
const http = require('http'); const http = require('http');
const app = express(); const app = express();
const port = process.env.PORT || 3000;
if (process.argv.includes('--rate-limit')) { if (process.argv.includes('--rate-limit')) {
const limiter = RateLimit({ const limiter = RateLimit({
@ -83,7 +82,13 @@ app.get('/', (req, res) => {
}); });
const server = http.createServer(app); const server = http.createServer(app);
server.listen(port); const port = process.env.PORT || 3000;
if (process.argv.includes('--localhost-only')) {
server.listen(port, '127.0.0.1');
} else {
server.listen(port);
}
const parser = require('ua-parser-js'); const parser = require('ua-parser-js');
const { uniqueNamesGenerator, animals, colors } = require('unique-names-generator'); const { uniqueNamesGenerator, animals, colors } = require('unique-names-generator');

View file

@ -4,9 +4,8 @@
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"start": "node index.js public", "start": "node index.js",
"start:prod": "node index.js public --rate-limit --auto-restart", "start:prod": "node index.js --rate-limit --auto-restart"
"test": "echo \"Error: no test specified\" && exit 1"
}, },
"author": "", "author": "",
"license": "ISC", "license": "ISC",