How to use @podium/utils - 10 common examples

To help you get started, we’ve selected a few @podium/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github podium-lib / podlet / lib / podlet.js View on Github external
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));
github podium-lib / layout / lib / layout.js View on Github external
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);
            }
github podium-lib / podlet / example / misc-app-servers / hapi-plugin.js View on Github external
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 '';
                },
            },
        ]);
    }
};
github podium-lib / layout / lib / layout.js View on Github external
[_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);
    }
github podium-lib / podlet / lib / podlet.js View on Github external
[_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));
    }
github podium-lib / layout / lib / layout.js View on Github external
[_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);
    }
github podium-lib / podlet / lib / podlet.js View on Github external
[_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));
    }
github podium-lib / podlet / lib / podlet.js View on Github external
}

        // 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;
    }
github podium-lib / podlet / __tests__ / podlet.js View on Github external
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();
});
github podium-lib / podlet / __tests__ / podlet.js View on Github external
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);
});

@podium/utils

Common generic utility methods shared by @podium modules.

MIT
Latest version published 13 days ago

Package Health Score

78 / 100
Full package analysis