Skip to content

MadMed677/-madmed677-url-builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UrlBuilder

travis build

Intro

A modern Javascript library for NodeJS to build urls to applications

Installation

$ npm i --save @madmed677/url-builder

1 Import into your project

const {ApplicationUrlBuilder} = require('@madmed677/url-builder');

2: Configure all your routes in one single place. For an example: routes.js

const urlBuilder = new ApplicationUrlBuilder({
    applications: {
        installments: {
            protocol: 'https',
            host: 'kassa.yandex.ru'
        },
        checkout: {
            protocol: 'https',
            host: 'kassa.yandex.ru'
        },
        portal: {
            protocol: 'https',
            host: 'money.yandex.ru'
        }
    }
});

const routes = urlBuilder.routes({
    portal: {
        'main-page': {
            pathname: ''
        },
        'transfer-page': {
            pathname: 'transfer'
        },
        'transfer-search-page': {
            pathname: 'transfer/search',
            query: {
                param3: 'val3'
            }
        }
    }
});

module.exports = routes;

3: After that import your routes and build route by name. For an example: app.js

const routes = require('/path/to/routes');

const portalTransferPage = routes
    .application('portal')
    .action('transfer-page')
    .build()
;
// 'https://money.yandex.ru/transfer/'

const portalTransferSearchPage = routes
    .application('portal')
    .action('transfer-search-page')
    .build()
;
// 'https://money.yandex.ru/transfer/search?foo=baz'

const portalTransferSearchQueryPage = routes
    .application('portal')
    .action('transfer-search-page')
    .build({
        query: {
            param1: 'val1',
            param2: 'val2'
        },
        hash: 'some-hash'
    })
;
// 'https://money.yandex.ru/transfer/search?param1=val1&param2=val2&param3=val3#some-hash'

Releases

No releases published

Packages

No packages published