Skip to content

Commit

Permalink
Added ports.json support for Wire over HTTP
Browse files Browse the repository at this point in the history
See the related documentation included with this commit for more information (/docs/general/ports.rst).
  • Loading branch information
ZelnickB committed Aug 23, 2020
1 parent e1bf307 commit ad48d36
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions defaults/prefs/ports.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"wireHTTP": 80
}
12 changes: 12 additions & 0 deletions docs/general/ports.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*******************
The ports.json file
*******************

The ``ports.json`` file, located at ``/prefs/ports.json`` determines which ports Aluminum uses for different features. The acceptable keys and values are listed below. All values must be of type ``Number``.

A default configuration of ``ports.json`` is located at ``/defaults/prefs/ports.json``.

.. describe:: "wireHTTP"

| The port to use for Aluminum Wire over HTTP.
| **Default:** 80
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ To navigate the documentation, use the sidebar to the left. To return to this pa
:caption: General Documentation
:numbered:

general/ports


.. toctree::
Expand Down
5 changes: 3 additions & 2 deletions src/wire/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const os = require('os') // For retrieving operating system information (for err
const path = require('path') // For manipulating request paths
const mimeTypes = require('mime-types') // For sending the correct Content-Type HTTP header

const ports = JSON.parse(fs.readFileSync('../../prefs/ports.json', 'utf8'))
const errorPage = fs.readFileSync('../../defaults/errors/404.html', 'utf8') // Default error page content
const logo = fs.readFileSync('../../logo.svg', 'utf8')

Expand Down Expand Up @@ -50,7 +51,7 @@ function serverHandler (req, res) {
.replace(/\$osplatform\$/g, os.platform())
.replace(/\$ostype\$/g, os.type())
.replace(/\$osversion\$/g, os.release())
.replace(/\$port\$/g, '80')
.replace(/\$port\$/g, ports.wireHTTP.toString())
.replace(/\$errcode\$/, err.code)
.replace(/\$errno\$/, err.errno.toString())
.replace(/\$errmessage\$/, err.message)
Expand All @@ -65,4 +66,4 @@ function serverHandler (req, res) {
}

const server = http.createServer(serverHandler)
server.listen(80)
server.listen(ports.wireHTTP)

0 comments on commit ad48d36

Please sign in to comment.