yeps-virtual-host
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
tests
.editorconfig
.eslintrc
.gitignore
.istanbul.yml
.travis.yml
LICENSE
README.md
appveyor.yml
index.js
package.json

README.md

YEPS Virtual Host

It helps to work with different domains splitting http / https protocols

NPM

npm version Build Status Coverage Status Linux Build Windows Build

Dependency Status devDependency Status NSP Status

License GitHub stars GitHub forks GitHub issues Twitter

How to install

npm i -S yeps-virtual-host

How to use

YEPS config:

const App = require('yeps');
const VirtualHost = require('yeps-virtual-host');
const error = require('yeps-error');

const app = new App();
const vhost = new VirtualHost();

app.all([
    error();
]);

HTTP:

vhost
    .http('yeps.info')
    .then(async ctx => {
        ctx.res.statusCode = 200;
        ctx.res.end('homepage');     
    });

HTTPS:

vhost
    .https('yeps.info')
    .then(async ctx => {
        ctx.res.statusCode = 302;
        ctx.res.setHeader('Location', 'http://yeps.info/');
        ctx.res.end();     
    });

Any host:

vhost
    .any('*.yeps.info')
    .then(async ctx => {
        ctx.res.statusCode = 302;
        ctx.res.setHeader('Location', 'http://yeps.info/');
        ctx.res.end();      
    });    

All methods are wrappers for catch() method:

catch({ 
    domain, 
    protocol: '*|http|https' 
})

Example:

vhost
    .catch({ domain: '*.yeps.info', protocol: '*' })
    .then(async ctx => {
        ctx.res.statusCode = 302;
        ctx.res.setHeader('Location', 'http://yeps.info/');
        ctx.res.end();      
    });

Add virtual host to app:

app.then(vhost.resolve());

With router:

const Router = require('yeps-router');

const siteRouter = new Router();

siteRouter.get('/').then(async ctx => {
    ctx.res.statusCode = 200;
    ctx.res.end('homepage');     
});

vhost
    .http('yeps.info')
    .then(siteRouter.resolve());    


const apiRouter = new Router();

apiRouter.get('/').then(async ctx => {
    ctx.res.statusCode = 200;
    ctx.res.setHeader('Content-Type', 'application/json');
    ctx.res.end('{"status":"OK"}');     
});

vhost
    .http('api.yeps.info')
    .then(apiRouter.resolve()); 


app.then(vhost.resolve());

YEPS documentation