Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return async (req, res, next) => {
const incoming = new HttpIncoming(req, res);
try {
await this.process(incoming);
// if this is a proxy request then no further work should be done.
if (incoming.proxy) return;
// set "incoming" on res.locals.podium
objobj.set('locals.podium', incoming, res);
if (res.header) {
res.header('podlet-version', this.version);
}
res.podiumSend = (data, ...args) =>
res.send(this.render(incoming, data, ...args));
return async (req, res, next) => {
const incoming = new HttpIncoming(req, res, res.locals);
try {
await this.process(incoming);
// if this is a proxy request then no further work should be done.
if (incoming.proxy) return;
// set "incoming" on res.locals.podium
objobj.set('locals.podium', incoming, res);
res.podiumSend = (data, ...args) =>
res.send(this.render(incoming, data, ...args));
next();
} catch (error) {
next(error);
}
method: (request, h) => {
const response = request.response.output
? request.response.output
: request.response;
response.headers['podlet-version'] = podlet.version;
return h.continue;
},
});
// Decorate response with .podiumSend() method
server.decorate('toolkit', 'podiumSend', fragment => {
return this.request.app.podium.render(fragment);
});
// Mount proxy route
const pathname = utils.pathnameBuilder(
podlet._proxy.pathname,
podlet._proxy.prefix,
'/{path*}',
);
server.route([
{
method: '*',
path: pathname,
handler: async request => {
await podlet._proxy.process(request.app.podium);
return '';
},
},
]);
}
};
[_addCssAsset](options = {}) {
if (!options.value) {
const v = this[_compabillity](this.cssRoute);
return this[_sanitize](v, options.prefix);
}
const args = Object.assign({}, options, {pathname: this._pathname});
this.cssRoute.push(new AssetCss(args));
// deprecate
deprecateCssReturn();
return this[_sanitize](args.value, args.prefix);
}
[_addCssAsset](options = {}) {
if (!options.value) {
const v = this[_compabillity](this.cssRoute);
return this[_sanitize](v, options.prefix);
}
const args = Object.assign({}, options, {pathname: this._pathname});
this.cssRoute.push(new AssetCss(args));
// deprecate
return new CssDeprecation(this[_sanitize](args.value, args.prefix));
}
[_addJsAsset](options = {}) {
if (!options.value) {
const v = this[_compabillity](this.jsRoute);
return this[_sanitize](v, options.prefix);
}
const args = Object.assign({}, options, {pathname: this._pathname});
this.jsRoute.push(new AssetJs(args));
// deprecate
deprecateJsReturn();
return this[_sanitize](args.value, args.prefix);
}
[_addJsAsset](options = {}) {
if (!options.value) {
const v = this[_compabillity](this.jsRoute);
return this[_sanitize](v, options.prefix);
}
const args = Object.assign({}, options, {pathname: this._pathname});
this.jsRoute.push(new AssetJs(args));
// deprecate
return new JsDeprecation(this[_sanitize](args.value, args.prefix));
}
}
// Append development context
if (incoming.development) {
incoming.context = Object.assign(
this.baseContext,
{ mountOrigin: incoming.url.origin },
this.defaultContext,
);
this.log.debug(
`Appending a default context to inbound request "${JSON.stringify(
incoming.context,
)}"`,
);
} else {
incoming.context = utils.deserializeContext(
incoming.request.headers,
);
this.log.debug(
`Inbound request contains a context "${JSON.stringify(
incoming.context,
)}"`,
);
}
// Determin if the request should be proxied and do if so
if (incoming.development && proxy) {
await this.httpProxy.process(incoming);
}
return incoming;
}
test('res.podiumSend() - contructor argument "development" is set to "true" - should append default wireframe document', async () => {
const options = Object.assign({}, DEFAULT_OPTIONS, {
development: true,
});
const podlet = new Podlet(options);
const server = new FakeExpressServer(podlet, (req, res) => {
res.podiumSend('<h1>OK!</h1>');
});
await server.listen();
const result = await server.get({ raw: true });
const incoming = new HttpIncoming(SIMPLE_REQ, SIMPLE_RES);
expect(result.response).toEqual(template(incoming, '<h1>OK!</h1>'));
await server.close();
});
test('.process() - call method with HttpIncoming - should return HttpIncoming', async () => {
const podlet = new Podlet(DEFAULT_OPTIONS);
const incoming = new HttpIncoming(SIMPLE_REQ, SIMPLE_RES);
const result = await podlet.process(incoming);
expect(result).toEqual(incoming);
});