From e6b9e14260fddd9a2bb6e7b903390f337eb474c4 Mon Sep 17 00:00:00 2001 From: orthagonal Date: Tue, 7 May 2019 05:18:52 +0000 Subject: [PATCH] update deps --- index.js | 2 +- package.json | 8 ++++---- test.js | 49 ++++++++++++++++++++++++++++++------------------- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/index.js b/index.js index e7237d5..27ea511 100644 --- a/index.js +++ b/index.js @@ -14,7 +14,7 @@ const register = function (server, pluginOptions) { if (redirect) { return h - .redirect('https://' + host + request.url.path) + .redirect(`https://${host}${request.url.pathname}${request.url.search}`) .code(301) .takeover(); } diff --git a/package.json b/package.json index 5edd9a0..b9d041d 100644 --- a/package.json +++ b/package.json @@ -27,10 +27,10 @@ }, "homepage": "https://github.com/bendrucker/hapi-require-https", "devDependencies": { - "hapi": "^16.0.1", - "standard": "^8.0.0", - "tape": "~4.6.0", - "test-peer-range": "~1.0.1" + "hapi": "^18.1.0", + "standard": "^12.0.1", + "tape": "^4.10.1", + "test-peer-range": "^2.0.0" }, "files": [ "*.js" diff --git a/test.js b/test.js index d8d64eb..6dc4102 100644 --- a/test.js +++ b/test.js @@ -5,9 +5,26 @@ var hapi = require('hapi') var http = require('http') var plugin = require('./index.js') -test('proxied requests', async (t) => { - t.plan(2) +const Server = async (options) => { + const server = new hapi.Server({ + debug: { + request: ['error'] + }, + port: 8080 + }); + await server.register({ plugin, options }); + server.route({ + method: 'GET', + path: '/', + handler: function (request, reply) { + return 'Hello!'; + } + }); + await server.start(); + return server; +}; +test('proxied requests', async (t) => { const server = await Server(); const response = await server.inject({ url: '/', @@ -18,10 +35,11 @@ test('proxied requests', async (t) => { }); t.equal(response.statusCode, 301, 'sets 301 code') t.equal(response.headers.location, 'https://host/', 'sets Location header') + await server.stop(); + t.end(); }); test('un-proxied requests: options = {proxy: false}', async (t) => { - t.plan(2) const server = await Server({ proxy: false }); const response = await server.inject({ url: '/', @@ -31,10 +49,11 @@ test('un-proxied requests: options = {proxy: false}', async (t) => { }); t.equal(response.statusCode, 301, 'sets 301 code') t.equal(response.headers.location, 'https://host/', 'sets Location header') + await server.stop(); + t.end(); }); test('query string', async (t) => { - t.plan(2) const server = await Server(); const response = await server.inject({ @@ -50,10 +69,11 @@ test('query string', async (t) => { 'https://host/?test=test&test2=test2', 'sets Location header with query string' ) + await server.stop(); + t.end(); }); test('ignores unmatched', async (t) => { - t.plan(2) const server = await Server(); const response = await server.inject({ @@ -65,10 +85,12 @@ test('ignores unmatched', async (t) => { }); t.equal(response.statusCode, 200, 'receives 200'); t.equal(response.result, 'Hello!', 'receives body'); + await server.stop(); + t.end(); + }); test('x-forward-host support', async (t) => { - t.plan(2) const server = await Server(); const response = await server.inject({ @@ -81,17 +103,6 @@ test('x-forward-host support', async (t) => { }); t.equal(response.statusCode, 301, 'sets 301 code') t.equal(response.headers.location, 'https://host2/', 'sets Location header') + await server.stop(); + t.end(); }); - -const Server = async (options) => { - const server = new hapi.Server(); - await server.register({ plugin, options }); - server.route({ - method: 'GET', - path: '/', - handler: function (request, h) { - return 'Hello!'; - } - }) - return server; -}