Verified Commit a2be859d authored by Aral Balkan's avatar Aral Balkan
Browse files

Local server can how be accessed over external IPv4 address.

This means that you can now test with other devices on your local area network without having to expose your server over the wide area network / Internet.
parent c8d1bd36
......@@ -5,9 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
## [5.2.0] - 2020-07-06
Nothing yet.
### Added
- Local server can how be accessed over external IPv4 address. This means that you can now test with other devices on your local area network without having to expose your server over the wide area network / Internet.
## [5.1.2] - 2020-06-16
......
......@@ -96,12 +96,24 @@ class AutoEncryptLocalhost {
log(' 📜 ❨auto-encrypt-localhost❩ Local certificate authority created.')
// Create the local certificate.
log(' 📜 ❨auto-encrypt-localhost❩ Creating local TLS certificates using mkcert…')
const createCertificateArguments = [
// Support all local interfaces so that the machine can be reached over the local network via IPv4.
// This is very useful for testing with multiple devices over the local area network without needing to expose
// the machine over the wide area network/Internet using a service like ngrok.
const localIPv4Addresses =
Object.entries(os.networkInterfaces())
.map(iface =>
iface[1].filter(addresses =>
addresses.family === 'IPv4')
.map(addresses => addresses.address)).flat()
const certificateDetails = [
`-key-file=${keyFilePath}`,
`-cert-file=${certFilePath}`,
'localhost', '127.0.0.1', '::1'
]
childProcess.execFileSync(mkcertBinary, createCertificateArguments, mkcertProcessOptions)
'localhost'
].concat(localIPv4Addresses)
childProcess.execFileSync(mkcertBinary, certificateDetails, mkcertProcessOptions)
log(' 📜 ❨auto-encrypt-localhost❩ Local TLS certificates created.')
} catch (error) {
log('\n', error)
......
{
"name": "@small-tech/auto-encrypt-localhost",
"version": "5.1.2",
"version": "5.2.0",
"description": "Automatically provisions and installs locally-trusted TLS certificates for Node.js https servers (including Express.js, etc.) using mkcert.",
"keywords": [
"mkcert",
......
......@@ -7,6 +7,12 @@ const AutoEncryptLocalhost = require('..')
const getHttpsString = bent('GET', 'string')
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}
test('certificate creation', async t => {
// t.plan(12)
......@@ -45,7 +51,20 @@ test('certificate creation', async t => {
const response = await getHttpsString('https://localhost')
t.strictEquals(response, 'ok', 'The response from the server is as expected.')
t.strictEquals(response, 'ok', 'Response from server is as expected for access via localhost.')
// Test access from all local interfaces with IPv4 addresses.
const localIPv4Addresses =
Object.entries(os.networkInterfaces())
.map(iface =>
iface[1].filter(addresses =>
addresses.family === 'IPv4')
.map(addresses => addresses.address)).flat()
await asyncForEach(localIPv4Addresses, async localIPv4Address => {
const response = await getHttpsString(`https://${localIPv4Address}`)
t.strictEquals(response, 'ok', `Response from server is as expected for access via ${localIPv4Address}`)
})
server.close()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment