Skip to content

Commit a6a15e0

Browse files
authored
Merge pull request #902 from ahihi/listen-address-options
Support 'host' & 'path' config options
2 parents 53a846b + 70e8df5 commit a6a15e0

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ There are some config settings you need to change in the files below.
170170
| `DEBUG` | `true` or `false` | set debug mode; show more logs |
171171
| `CMD_DOMAIN` | `codimd.org` | domain name |
172172
| `CMD_URL_PATH` | `codimd` | sub URL path, like `www.example.com/<URL_PATH>` |
173+
| `CMD_HOST` | `localhost` | host to listen on |
173174
| `CMD_PORT` | `80` | web app port |
175+
| `CMD_PATH` | `/var/run/codimd.sock` | path to UNIX domain socket to listen on (if specified, `CMD_HOST` and `CMD_PORT` are ignored) |
174176
| `CMD_ALLOW_ORIGIN` | `localhost, codimd.org` | domain name whitelist (use comma to separate) |
175177
| `CMD_PROTOCOL_USESSL` | `true` or `false` | set to use SSL protocol for resources path (only applied when domain is set) |
176178
| `CMD_URL_ADDPORT` | `true` or `false` | set to add port on callback URL (ports `80` or `443` won't be applied) (only applied when domain is set) |
@@ -252,7 +254,9 @@ There are some config settings you need to change in the files below.
252254
| `debug` | `true` or `false` | set debug mode, show more logs |
253255
| `domain` | `localhost` | domain name |
254256
| `urlPath` | `codimd` | sub URL path, like `www.example.com/<urlpath>` |
257+
| `host` | `localhost` | host to listen on |
255258
| `port` | `80` | web app port |
259+
| `path` | `/var/run/codimd.sock` | path to UNIX domain socket to listen on (if specified, `host` and `port` are ignored) |
256260
| `allowOrigin` | `['localhost']` | domain name whitelist |
257261
| `useSSL` | `true` or `false` | set to use SSL server (if `true`, will auto turn on `protocolUseSSL`) |
258262
| `hsts` | `{"enable": true, "maxAgeSeconds": 31536000, "includeSubdomains": true, "preload": true}` | [HSTS](https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security) options to use with HTTPS (default is the example value, max age is a year) |

app.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,21 @@ io.sockets.on('connection', realtime.connection)
205205

206206
// listen
207207
function startListen () {
208-
server.listen(config.port, function () {
208+
var address
209+
var listenCallback = function () {
209210
var schema = config.useSSL ? 'HTTPS' : 'HTTP'
210-
logger.info('%s Server listening at port %d', schema, config.port)
211+
logger.info('%s Server listening at %s', schema, address)
211212
realtime.maintenance = false
212-
})
213+
}
214+
215+
// use unix domain socket if 'path' is specified
216+
if (config.path) {
217+
address = config.path
218+
server.listen(config.path, listenCallback)
219+
} else {
220+
address = config.host + ':' + config.port
221+
server.listen(config.port, config.host, listenCallback)
222+
}
213223
}
214224

215225
// sync db then start listen

lib/config/default.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module.exports = {
44
domain: '',
55
urlPath: '',
6+
host: '0.0.0.0',
67
port: 3000,
78
urlAddPort: false,
89
allowOrigin: ['localhost'],

lib/config/environment.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ const {toBooleanConfig, toArrayConfig, toIntegerConfig} = require('./utils')
55
module.exports = {
66
domain: process.env.CMD_DOMAIN,
77
urlPath: process.env.CMD_URL_PATH,
8+
host: process.env.CMD_HOST,
89
port: toIntegerConfig(process.env.CMD_PORT),
10+
path: process.env.CMD_PATH,
911
urlAddPort: toBooleanConfig(process.env.CMD_URL_ADDPORT),
1012
useSSL: toBooleanConfig(process.env.CMD_USESSL),
1113
hsts: {

0 commit comments

Comments
 (0)