1.0.7 • Published 4 years ago

express-sub v1.0.7

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

express-sub

An easy and simple subdomain routing.

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install express-sub

API

var { root, sub } = require('express-sub')

Usage

Root

localhost:

root(route)

localhost domain:

root(route, 'domain')

Subdomain

Subdomain Routing is not support *. because it's simple

sub('subdomain', route)

Sample

const
    express = require('express'),
    { root, sub } = require('express-sub'),
    app = express(),
    main = express.Router(),
    api = express.Router()

main
    .get('*', (req, res) => {
        res.send(`This is main`)
    })

api
    .get('*', (req, res) => {
        res.send(`This is api`)
    })

app
    .use(sub('api.', api)) // <-- route for api subdomain
    .use(sub('www.', main)) // <-- route for www subdomain
    .use(root(main, 'example.com')) // <-- route for root domain

    .use((req, res, callback) => {
        res.status(404).send(`404`)
    })

app.listen(80, () => {
    console.log(`App listening on port 80`)
})
1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago