Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
8 changes: 4 additions & 4 deletions 8 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
49 changes: 30 additions & 19 deletions 49 test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '/',
Expand All @@ -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: '/',
Expand All @@ -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({
Expand All @@ -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({
Expand All @@ -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({
Expand All @@ -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;
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.