Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integrated tests #10

Merged
merged 18 commits into from
Apr 9, 2024
8 changes: 8 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
HTTP_PORT=8880
HTTPS_PORT=8843
STAT_PORT=8081
WHITELIST_HOSTS=
BLACKLIST_HOSTS="bad.example,evil.example"
BLACKLIST_REDIRECT="https://forwarddomain.net/blacklisted"
NODE_ENV=test
NODE_TLS_REJECT_UNAUTHORIZED=0
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Auto detect text files and perform LF normalization
* text=auto
go.mod eol=lf text=auto
go.sum eol=lf text=auto
package.json eol=lf text=auto
*.lockb binary diff=lockb
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

on:
push:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '^1.22.1'
- name: Install pebble
run: go install github.com/letsencrypt/pebble/v2/cmd/[email protected]
- name: Install dnsserver
run: go install github.com/dlorch/dnsserver@latest
- name: Install deps
run: npm install
- name: Test
run: env PATH=${PATH}:`go env GOPATH`/bin npm test
12 changes: 9 additions & 3 deletions HOSTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ This guide will walk you through the process of setting up your own instance of

## Prerequisites

- [Node.js](https://nodejs.org/en/) (version 16 or higher).
- A machine with public IP address installed.
- `node` LTS node (20.x or Higher)
- `openssl` required for signing certs
- `go` (>= 1.22) for running tests
- `find`, `grep`, `wc` (linux standard tools) for running stats
- A machine with public IP address installed

## Installation

Expand All @@ -26,6 +29,7 @@ This guide will walk you through the process of setting up your own instance of
`WHITELIST_HOSTS` | A comma-separated list of root domains to whitelist
`BLACKLIST_HOSTS` | A comma-separated list of root domains to blacklist
`BLACKLIST_REDIRECT` | The URL to redirect to when a blacklisted host is accessed
`OPENSSL_BIN` | (used by `pem` package) Path to `openssl` to override from PATH

If `WHITELIST_HOSTS` is set, `BLACKLIST_HOSTS` is ignored. Both is mutually exclusive.

Expand All @@ -45,10 +49,12 @@ SSL certificates is saved in `./.certs` directory. No additional configuration i

`sudo npm start` is recommended to run the app. This is because the app needs to listen to port 80 and 443 directly, which requires root access.

If you want to run the app without root access, or wanted to filter some domains for other services, you have to use NGINX with stream plugin
If you want to run the app without root access, or wanted to filter some domains for other services, you have to use NGINX with stream plugin.

## NGINX + Stream Plugin

You cannot run this server via regular NGINX's `server` directive because that's mean you won't get benefited from automatic HTTPS cert installation and only-DNS-needed setup approach.

[NGINX Stream plugin](http://nginx.org/en/docs/stream/ngx_stream_core_module.html) is used to filter some domain while still be able forwards HTTPS connection directly. It has to be that way since NGINX doesn't handle HTTPS certificates.

This configuration below, setups the following:
Expand Down
7 changes: 3 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import "dotenv/config.js";
import {plainServer, secureServer} from "./index.js";

const port80 = parseInt(process.env.HTTP_PORT || "80");
const port443 = parseInt(process.env.HTTPS_PORT || "443");

const port80 = parseInt(process.env.HTTP_PORT || "8080");
const port443 = parseInt(process.env.HTTPS_PORT || "8443");
console.log("Forward Domain running with env", process.env.NODE_ENV);
plainServer.listen(port80, () => console.log(`HTTP server start at port ${port80}`));
secureServer.listen(port443, () => console.log(`HTTPS server start at port ${port443}`));
4 changes: 0 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ const secureServer = https.createServer({
secureServer.on('listening', SniPrepare);

if (isMainProcess(import.meta.url)) {
import ("dotenv/config.js");
const port = parseInt(process.env.HTTP_PORT || "3000");
plainServer.listen(port, function () {
console.log(`HTTP server start at port ${port}`);
});
}

// default export is to be deprecated
export default plainServer;

export {
plainServer,
secureServer
Expand Down
Loading
Loading