Skip to content

Commit

Permalink
feat: Prefix environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mfeltscher committed Feb 21, 2022
1 parent c5f917b commit f7dc41a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ services:
image: smartive/mockserver
environment:
MOCK_PATH: /mock
HOST: 0.0.0.0
PORT: 1080
MOCK_HOST: 0.0.0.0
MOCK_HTTP_PORT: 1080
```

## HTTPS

Set a `HTTPS_PORT` env variable to start an https server as well.
Set a `MOCK_HTTPS_PORT` env variable to start an https server as well.
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ const http = require('http');
const https = require('https');
const { readFileSync } = require('fs');

const HTTP_PORT = process.env.PORT || 1080;
const HTTPS_PORT = process.env.HTTPS_PORT;
const SMTP_PORT = process.env.SMTP_PORT || '25';
const HOST = process.env.HOST || '0.0.0.0';
const HTTP_PORT = process.env.MOCK_HTTP_PORT || process.env.PORT || 1080;
const HTTPS_PORT = process.env.MOCK_HTTPS_PORT || process.env.HTTPS_PORT;
const SMTP_PORT = process.env.MOCK_SMTP_PORT || process.env.SMTP_PORT || '25';
const HOST = process.env.MOCK_HOST || process.env.HOST || '0.0.0.0';
const MOCK_PATH = process.env.MOCK_PATH || '/mock';

let routes = [];
let calls = [];
Expand Down Expand Up @@ -64,7 +65,7 @@ const smtpServer = new SMTPServer({
smtpServer.listen(SMTP_PORT, HOST);

const route = express.Router();
app.use(process.env.MOCK_PATH || '/mock', route);
app.use(MOCK_PATH, route);

const streamToString = (readStream) =>
new Promise((res) => {
Expand Down

0 comments on commit f7dc41a

Please sign in to comment.