From b7c46ac324172449770c34a07a31cb639cf4f402 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Sun, 29 Sep 2024 20:46:45 -0400 Subject: [PATCH] test: add localhost addresses test --- test/localhost.test.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/localhost.test.js diff --git a/test/localhost.test.js b/test/localhost.test.js new file mode 100644 index 00000000..23facf49 --- /dev/null +++ b/test/localhost.test.js @@ -0,0 +1,28 @@ +'use strict'; + +const test = require('tap').test; +const ecstatic = require('../lib/core'); +const http = require('http'); +const request = require('request'); + +test('can connect from all localhost addresses', t => { + const server = http.createServer(ecstatic(`${__dirname}/public/subdir`)); + t.on('end', () => { server.close(); }); + server.listen(0, () => { + const port = server.address().port; + const addresses = [ + 'localhost', + '127.0.0.1', + '::1', + ]; + + t.plan(addresses.length * 2); + + for (const address of addresses) { + request.get(`http://${address}:${port}/index.html`, (err, res, body) => { + t.error(err); + t.equal(res.statusCode, 200); + }); + } + }); +}); \ No newline at end of file