@pyramation/url-domains

0.1.0 • Public • Published

url domains

for use with express

why?

Because, express requires that you do things like this when you need req.subdomains on localhost:

  if (env.SERVER_HOST === 'localhost') {
    app.set('subdomain offset', 1);
  }

and I believe the developer experience shouldn't include any off-by-one errors imo if you forgot this or your environments are changing and/or dynamic.

So why not just make a subdomains object you can trust no matter what?

install

yarn add @pyramation/url-domains

middleware

  import {
    middleware as parseDomains
  } from '@pyramation/url-domains';


  app.use(parseDomains());

  app.use(async (req, res, next) => {
    // have fun!
    await fn(req.urlDomains.domain, req.urlDomains.subdomains);
  });

manual usage

  import {
    parseReq
  } from '@pyramation/url-domains';

  app.use(async (req, res, next) => {
    const {
        domain,
        subdomains
    } = parseReq(req);

    // cheers!!
    await fn(domain, subdomains);
  });

Readme

Keywords

none

Package Sidebar

Install

npm i @pyramation/url-domains

Weekly Downloads

17

Version

0.1.0

License

SEE LICENSE IN LICENSE

Unpacked Size

9.76 kB

Total Files

11

Last publish

Collaborators

  • pyramation