How to use the hyperswitch.URI function in hyperswitch

To help you get started, we’ve selected a few hyperswitch 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 wikimedia / restbase / lib / revision_table_access_check_filter.js View on Github external
.then((res) => {
        const revision = res.body.items[0];

        if (revision.redirect && req.query.redirect !== false) {
            const htmlPath = [rp.domain, 'sys', 'parsoid', 'html', rp[titleParamName]];
            if (rp.revision) {
                htmlPath.push(`${rp.revision}`);
                if (rp.tid) {
                    htmlPath.push(`${rp.tid}`);
                }
            }
            return hyper.get({
                uri: new URI(htmlPath),
            })
            .then((html) => {
                const redirectTitle = mwUtil.extractRedirect(html.body)
                    // Redirect detected while saving new HTML.
                    || html.headers.location;
                if (redirectTitle) {
                    const newParams = Object.assign({}, rp);
                    newParams[titleParamName] = redirectTitle;
                    const location = mwUtil.createRelativeTitleRedirect(specInfo.path, req, {
                        newReqParams: newParams,
                        titleParamName,
                        dropPathAfterTitle: true,
                    });

                    let contentPromise;
                    if (options.attach_body_to_redirect) {
github wikimedia / restbase / lib / access_check_filter.js View on Github external
.then((res) => {
        const revision = res.body.items[0];

        if (revision.redirect && req.query.redirect !== false) {
            const htmlPath = [rp.domain, 'sys', 'parsoid', 'html', rp[titleParamName]];
            if (rp.revision) {
                htmlPath.push(`${rp.revision}`);
                if (rp.tid) {
                    htmlPath.push(`${rp.tid}`);
                }
            }
            return hyper.get({
                uri: new URI(htmlPath)
            })
            .then((html) => {
                const redirectTitle = mwUtil.extractRedirect(html.body) ||
                    // Redirect detected while saving new HTML.
                    html.headers.location;
                if (redirectTitle) {
                    const newParams = Object.assign({}, rp);
                    newParams[titleParamName] = redirectTitle;
                    const location = mwUtil.createRelativeTitleRedirect(specInfo.path, req, {
                        newReqParams: newParams,
                        titleParamName,
                        dropPathAfterTitle: true
                    });

                    let contentPromise;
                    if (options.attach_body_to_redirect) {
github wikimedia / restbase / test / features / specification / monitoring.js View on Github external
.forEach((method) => {
            const p = paths[pathStr][method];
            const uri = new URI(`${server.config.hostPort}/{domain}/v1${pathStr}`, {}, true);
            if (!p['x-amples']) {
                throw new Error(`${'Method without examples should declare x-monitor: false.'
                    + ' Path: '}${pathStr} Method: ${method}`);
            }
            p['x-amples'].forEach((ex) => {
                ex.request = ex.request || {};
                ex.request.params = ex.request.params || {};
                ex.request.params.domain = ex.request.params.domain ?
                    betaDomain(ex.request.params.domain) : options.domain;
                if (ex.request.params.domain !== options.domain) {
                    return;
                }

                ret.push(constructTestCase(
                    ex.title,
                    uri.toString({
github wikimedia / restbase / lib / access_check_filter.js View on Github external
delete res.headers.location;
        }
        return res;
    });

    if (mwUtil.isNoCacheRequest(req)) {
        return continueRequest();
    }

    const titleParamName = options.title ? options.title : 'title';
    const checkURIParts = [rp.domain, 'sys', 'page_revisions', 'page', rp[titleParamName]];
    if (rp.revision) {
        checkURIParts.push(`${rp.revision}`);
    }

    return hyper.get({ uri: new URI(checkURIParts) })
    .then((res) => {
        const revision = res.body.items[0];

        if (revision.redirect && req.query.redirect !== false) {
            const htmlPath = [rp.domain, 'sys', 'parsoid', 'html', rp[titleParamName]];
            if (rp.revision) {
                htmlPath.push(`${rp.revision}`);
                if (rp.tid) {
                    htmlPath.push(`${rp.tid}`);
                }
            }
            return hyper.get({
                uri: new URI(htmlPath)
            })
            .then((html) => {
                const redirectTitle = mwUtil.extractRedirect(html.body) ||
github wikimedia / restbase / v1 / summary_proxy.js View on Github external
getSummary: (hyper, req) => {
                const rp = req.params;
                const oldURI = new URI([rp.domain, 'sys', 'summary_old', 'summary', rp.title]);
                const newURI = new URI([rp.domain, 'sys', 'summary_new', 'summary', rp.title]);
                if (mwUtil.isNoCacheRequest(req) && isNewStorageEnabled(req.params.domain)) {
                    return P.props({
                        oldContent: hyper.get({
                            uri: oldURI,
                            headers: req.headers,
                            query: req.query
                        }),
                        newContent: hyper.get({
                            uri: newURI,
                            headers: req.headers,
                            query: req.query
                        })
                        .catch((e) => {
                            hyper.log('error/summary_proxy', {
                                msg: 'New content fetch failure',
                                error: e
github wikimedia / restbase / v1 / summary_proxy.js View on Github external
getSummary: (hyper, req) => {
                const rp = req.params;
                const oldURI = new URI([rp.domain, 'sys', 'summary_old', 'summary', rp.title]);
                const newURI = new URI([rp.domain, 'sys', 'summary_new', 'summary', rp.title]);
                if (mwUtil.isNoCacheRequest(req) && isNewStorageEnabled(req.params.domain)) {
                    return P.props({
                        oldContent: hyper.get({
                            uri: oldURI,
                            headers: req.headers,
                            query: req.query
                        }),
                        newContent: hyper.get({
                            uri: newURI,
                            headers: req.headers,
                            query: req.query
                        })
                        .catch((e) => {
                            hyper.log('error/summary_proxy', {
                                msg: 'New content fetch failure',
github wikimedia / restbase / lib / revision_table_access_check_filter.js View on Github external
delete res.headers.location;
        }
        return res;
    });

    if (mwUtil.isNoCacheRequest(req)) {
        return continueRequest();
    }

    const titleParamName = options.title ? options.title : 'title';
    const checkURIParts = [rp.domain, 'sys', 'page_revisions', 'page', rp[titleParamName]];
    if (rp.revision) {
        checkURIParts.push(`${rp.revision}`);
    }

    return hyper.get({ uri: new URI(checkURIParts) })
    .then((res) => {
        const revision = res.body.items[0];

        if (revision.redirect && req.query.redirect !== false) {
            const htmlPath = [rp.domain, 'sys', 'parsoid', 'html', rp[titleParamName]];
            if (rp.revision) {
                htmlPath.push(`${rp.revision}`);
                if (rp.tid) {
                    htmlPath.push(`${rp.tid}`);
                }
            }
            return hyper.get({
                uri: new URI(htmlPath),
            })
            .then((html) => {
                const redirectTitle = mwUtil.extractRedirect(html.body)

hyperswitch

REST API creation framework

Apache-2.0
Latest version published 4 years ago

Package Health Score

46 / 100
Full package analysis