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);
}
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);
});
test('.process() - call method with HttpIncoming - should return HttpIncoming', async () => {
const layout = new Layout(DEFAULT_OPTIONS);
const incoming = new HttpIncoming(SIMPLE_REQ, SIMPLE_RES);
const result = await layout.process(incoming);
expect(result).toEqual(incoming);
});
/*
this.app = http.createServer(async (req, res) => {
const incoming = new HttpIncoming(req, res);
const result = await podlet.process(incoming, process);
onRequest
? onRequest(result)
: result => {
result.response.status(200).json(result);
};
});
this.server = undefined;