trinte-subdomain
v0.0.2
Published
Subdomain Middleware for TrinteJS & ExpressJS Javascript Frameworks.
Downloads
6
Maintainers
Readme
Subdomain Middleware for TrinteJS
Subdomain Middleware for TrinteJS & ExpressJS Javascript Frameworks.
Installation
npm install trinte-subdomain --save
Usage overview
for TrinteJS
setup middleware in project config/middleware.js
var subdomain = require('trinte-subdomain');
module.exports = function (app, express) {
app.use(subdomain({
base: 'mydomain.dev',
only : '(test|admin)',
except : '(group|panel|my)',
onSuccess: function(req, res, next){
console.log('onSuccess');
next();
},
onExcept: function(req, res, next){
console.log('onExcept');
next();
},
alias: {
'.*': 'admin'
}
}));
...
}
usage for namespace in project config/routes.js
module.exports = function routes(map, app) {
map.namespace('admin', {
subdomain: true
}, function(admin) {
admin.resources('users');
});
...
});
for ExpressJS
var express = require('express');
var app = express();
var subdomain = require('trinte-subdomain');
...
app.use(subdomain({
base: 'mydomain.dev',
only : '(test|admin)',
except : '(group|panel|my)',
onSuccess: function(req, res, next){
console.log('onSuccess');
next();
},
onExcept: function(req, res, next){
console.log('onExcept');
next();
},
alias: {
'.*': 'admin'
}
}));
app.get('/subdomain/admin', function(req, res){
res.send('Ok!');
});
app.listen(3000);
Tests
npm test
Options
</td>
<td>
Base damain name (required)
</td>
</tr>
<tr>
<td>
only
</td>
<td>
string
</td>
<td>
null
</td>
<td>
Rewrite `url` only for specified subdomains
</td>
</tr>
<tr>
<td>
except
</td>
<td>
string
</td>
<td>
null
</td>
<td>
Don`t rewrite `url` for specified subdomains
</td>
</tr>
<tr>
<td>
onSuccess
</td>
<td>
function
</td>
<td>
null
</td>
<td>
Call this function if `url` rewrited
</td>
</tr>
<tr>
<td>
onExcept
</td>
<td>
function
</td>
<td>
</td>
<td>
Call this function if `except` param test true
</td>
</tr>
<tr>
<td>
alias
</td>
<td>
object
</td>
<td>
null
</td>
<td>
Subdomains mapping like:
```
{
alias: {
'(admin|backend)': 'admin'
}
}
```
</td>
</tr>
Copyright & License
(The MIT License)
Copyright (c) 2013 Alexey Gordeyev
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Resources
- Visit the author website.
- Follow @biggora on Twitter for updates.
- Follow agbiggora on Facebook for updates.
- Report issues on the github issues page.