@hitachi567/subdomain
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Subdomain

hitachi567 <abidai790@gmail.com>

Express middleware for handle request from subdomain

Requirements

  • node.js
  • npm or yarn

Getting started

npm install @hitachi567/subdomain

# or

yarn add @hitachi567/subdomain

Usage

import subdomain from '@hitachi567/subdomain';
import express from 'express';

let app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

app.set('subdomain offset', 3); // mydomain.tld.com
app.set('subdomain offset', 2); // mydomain.com
app.set('subdomain offset', 1); // localhost

app.use(subdomain(
    (req, res) => res.send(req.hostname),
    ['api', 'users']
));

app.use(subdomain(
    (req, res) => res.send(req.hostname),
    ['api', 'posts']
));

app.use(subdomain(
    (req, res) => res.send(req.hostname)
));

app.listen(5000, () => {
    console.log('Server started on http://localhost:5000')
});

Links

Readme

Keywords

Package Sidebar

Install

npm i @hitachi567/subdomain

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

6.84 kB

Total Files

8

Last publish

Collaborators

  • hitachi567