@hitachi567/subdomain
v1.0.0
Published
middleware for handle request from subdomain
Downloads
2
Readme
Subdomain
hitachi567 <[email protected]>
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')
});