You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

hapi-transform-table

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-transform-table - npm Package Compare versions

Comparing version

to
1.5.4

22

index.js
const jsonToTable = require('json-to-table');
const os = require('os');
const qs = require('querystring');

@@ -18,3 +19,11 @@ const register = (server, pluginOptions) => {

request.headers.accept = 'text/html';
request.setUrl(request.path.replace('.html', ''));
let newUrl = request.path.replace('.html', '');
// save the original path info:
request.app.transformTable = {
originalPath: newUrl
};
if (Object.keys(query).length) {
newUrl = `${newUrl}?${qs.stringify(query)}`;
}
request.setUrl(newUrl);
request.query = query;

@@ -26,8 +35,11 @@ }

const response = request.response;
if (response.isBoom) {
if (response.isBoom || response.statusCode !== 200) {
// if this was originally a .html request and it got redirected,
// add back the .html before returning it
if (request.app.transformTable && [301, 302].includes(response.statusCode)) {
const originalPath = request.app.transformTable.originalPath;
response.headers.location = response.headers.location.replace(originalPath, `${originalPath}.html`);
}
return h.continue;
}
if (response.statusCode !== 200) {
return h.continue;
}
if (request.headers.accept === 'text/html') {

@@ -34,0 +46,0 @@ const routeOptions = request.route.settings.plugins['hapi-transform-table'] || {};

{
"name": "hapi-transform-table",
"version": "1.5.3",
"version": "1.5.4",
"description": "hapi plugin for routes that need to return json as HTML tables ",

@@ -27,4 +27,5 @@ "main": "index.js",

"hapi": "^17.2.0",
"hapi-password": "^5.1.0",
"tap": "^11.0.1"
}
}

@@ -344,2 +344,3 @@ const Hapi = require('hapi');

handler(request, h) {
t.equal(request.url.path, '/path1?test=1');
t.equal(request.query.test, '1', 'query param forwarded');

@@ -359,1 +360,30 @@ return [];

});
tap.test('auth schemes that do redirects will preserve the original .html route', async(t) => {
const server = await new Hapi.Server({ port: 8080 });
await server.register(plugin, {});
await server.register({
plugin: require('hapi-password'),
options: {
salt: 'aSalt',
password: 'password',
cookieName: 'demo-login'
}
});
server.route({
method: 'GET',
path: '/success',
config: {
plugins: {
'hapi-transform-table': {}
},
handler: (request, h) => 'success!'
}
});
await server.start();
const redirectResponse = await server.inject({ url: '/success.html' });
t.equal(redirectResponse.statusCode, 302);
t.equal(redirectResponse.headers.location, '/login?next=/success.html');
await server.stop();
t.end();
});