How to use the urijs.joinPaths function in urijs

To help you get started, we’ve selected a few urijs 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 astefanutti / kubebox / lib / client.js View on Github external
return Object.keys(source).reduce((target, key) => {
    const prop = source[key];
    if (typeof prop === 'object' && Object.prototype.toString.call(prop) === '[object Object]') {
      // Only deep copy Object
      if (!target[key]) target[key] = {};
      merge(target[key], prop);
    } else if (key === 'path') {
      target.path = URI.joinPaths(target.path || '', source.path || '')
        .setQuery(URI.parseQuery(URI.parse(target.path || '').query || ''))
        .setQuery(URI.parseQuery(URI.parse(source.path || '').query || ''))
        .resource();
    } else {
      target[key] = prop;
    }
    return target;
  }, target);
}
github LotusTM / Kotsu / modules / urljoin.js View on Github external
module.exports = (...urls) => {
  const [firstUrl, ...restUrls] = urls
  const uri = URI(firstUrl)
  const hasProtocol = uri.protocol()

  if (hasProtocol) {
    // @todo Something has to be done with the fact that URI.js force-encodes urls
    //       https://github.com/LotusTM/Kotsu/issues/322
    return URI.decode(URI.joinPaths(...restUrls).absoluteTo(uri).valueOf())
  }

  let path = URI.joinPaths(...urls).valueOf()

  // @todo Workaround for https://github.com/medialize/URI.js/issues/341
  if (!path.startsWith('/') && firstUrl === '/') {
    path = `/${path}`
  }

  return URI.decode(path)
}
github astefanutti / kubebox / lib / auth / oidc.js View on Github external
provider_configuration_options() {
    // https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfig
    const options = URI.parse(this.auth_provider.url);
    if (this.auth_provider.ca) options.ca = this.auth_provider.ca;
    options.path = URI.joinPaths(options.path, '.well-known/openid-configuration');
    options.protocol += ':';
    return options;
  }
github Graylog2 / graylog2-server / graylog2-web-interface / src / webpack-entry.js View on Github external
import URI from 'urijs';
import AppConfig from 'util/AppConfig';

// The webpack-dev-server serves the assets from "/"
const assetPrefix = AppConfig.gl2DevMode() ? '/' : '/assets/';

// If app prefix was not set, we need to tell webpack to load chunks from root instead of the relative URL path
// eslint-disable-next-line camelcase, no-undef
__webpack_public_path__ = URI.joinPaths(AppConfig.gl2AppPathPrefix(), assetPrefix).path() || assetPrefix;
github solid / node-solid-server / lib / handlers / index.js View on Github external
async function handler (req, res, next) {
  const indexFile = 'index.html'
  const ldp = req.app.locals.ldp
  const negotiator = new Negotiator(req)
  const requestedType = negotiator.mediaType()

  try {
    const { path: filename } = await ldp.resourceMapper.mapUrlToFile({ url: req })

    const stats = await ldp.stat(filename)
    if (!stats.isDirectory()) {
      return next()
    }
    // redirect to the right container if missing trailing /
    if (req.path.lastIndexOf('/') !== req.path.length - 1) {
      return res.redirect(301, URI.joinPaths(req.path, '/').toString())
    }

    if (requestedType && requestedType.indexOf('text/html') !== 0) {
      return next()
    }
    debug('Looking for index in ' + req.path)

    // Check if file exists in first place
    await ldp.exists(req.hostname, path.join(req.path, indexFile))
    res.locals.path = url.resolve(req.path, indexFile)
    debug('Found an index for current path')
  } catch (e) {
    // Ignore errors
  }
  next()
}
github magda-io / magda / magda-gateway / src / createCkanRedirectionRouter.ts View on Github external
async function(req, res) {
            try {
                res.redirect(
                    301,
                    URI(req.originalUrl)
                        .domain(ckanRedirectionDomain)
                        .protocol("https")
                        .directory(
                            URI.joinPaths(
                                ckanRedirectionPath,
                                URI(req.originalUrl).directory()
                            ).toString()
                        )
                        .toString()
                );
            } catch (e) {
                console.log(e);
                showError(res, 500);
            }
        }
    );
github magda-io / magda / magda-web-server / src / buildSitemapRouter.ts View on Github external
.path(
                                URI.joinPaths(
                                    baseExternalUrl,
                                    "sitemap/dataset/afterToken",
                                    token.toString() + ".xml"
                                ).href()
                            )
                            .href();
                    });

                    const smi = sm.buildSitemapIndex({
                        urls: [
                            baseExternalUri
                                .clone()
                                .path(
                                    URI.joinPaths(
                                        baseExternalUrl,
                                        "sitemap/main.xml"
                                    ).href()
                                )
                                .href()
                        ].concat(datasetsPages)
                    });

                    res.send(smi);
                })
        );
github researchspace / researchspace / metaphacts-platform / web / src / main / components / forms / FormModel.ts View on Github external
const iriTemplate = template || DEFALUT_SUBJECT_TEMPLATE;
  const subject = iriTemplate.replace(/{{([^{}]+)}}/g, (match, placeholder) => {
    const p: Placeholder = (
      placeholder === 'UUID' ? {type: 'UUID'} :
      {type: 'FieldValue', id: placeholder}
    );
    return replacer(p, composite);
  });

  const isAbsoluteUri = URI(subject).scheme();
  if (isAbsoluteUri || !ownerSubject) {
    return Rdf.iri(subject);
  }

  const combinedPath = URI.joinPaths(ownerSubject.value, subject).toString();
  return Rdf.iri(URI(ownerSubject.value).pathname(combinedPath).toString());
}