Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Any Rule | 7,168 | 4 months ago | 26 | mit | TypeScript | |||||
🦕 常用正则大全, 支持web / vscode / idea / Alfred Workflow多平台 | ||||||||||
Path To Regexp | 7,062 | 534,174 | 4,747 | 10 months ago | 53 | May 06, 2022 | 16 | mit | TypeScript | |
Turn a path string such as `/user/:name` into a regular expression | ||||||||||
Next Routes | 2,439 | 686 | 78 | a month ago | 46 | May 21, 2018 | mit | JavaScript | ||
Universal dynamic routes for Next.js | ||||||||||
Vhost | 737 | 25,686 | 300 | 2 months ago | 7 | October 13, 2015 | 3 | mit | JavaScript | |
virtual domain hosting | ||||||||||
Pupperender | 103 | 4 | 1 | a year ago | 17 | October 02, 2021 | mit | JavaScript | ||
ExpressJs middleware for rendering PWA to bots using Puppeteer. | ||||||||||
Express Rewrite | 74 | 26 | 3 | 9 years ago | 4 | May 12, 2014 | 3 | other | JavaScript | |
Express middleware for rewriting URLs without doing an http redirect. | ||||||||||
Gulp Develop Server | 72 | 816 | 105 | 6 years ago | 27 | May 28, 2016 | 5 | mit | JavaScript | |
Development assistant for node.js server by gulp | ||||||||||
Idea Rule | 56 | a year ago | mit | Java | ||||||
基于IDEA平台的常用正则表达式插件 | ||||||||||
Regex | 46 | 9 years ago | C | |||||||
a regular express engine | ||||||||||
Express Urlrewrite | 43 | 4,056 | 246 | 2 months ago | 6 | March 08, 2022 | other | JavaScript | ||
URL rewriting middleware for express |
$ npm install vhost
var vhost = require('vhost')
Create a new middleware function to hand off request to handle
when the incoming
host for the request matches hostname
. The function is called as
handle(req, res, next)
, like a standard middleware.
hostname
can be a string or a RegExp object. When hostname
is a string it can
contain *
to match 1 or more characters in that section of the hostname. When
hostname
is a RegExp, it will be forced to case-insensitive (since hostnames are)
and will be forced to match based on the start and end of the hostname.
When host is matched and the request is sent down to a vhost handler, the req.vhost
property will be populated with an object. This object will have numeric properties
corresponding to each wildcard (or capture group if RegExp object provided) and the
hostname
that was matched.
var connect = require('connect')
var vhost = require('vhost')
var app = connect()
app.use(vhost('*.*.example.com', function handle (req, res, next) {
// for match of "foo.bar.example.com:8080" against "*.*.example.com":
console.dir(req.vhost.host) // => 'foo.bar.example.com:8080'
console.dir(req.vhost.hostname) // => 'foo.bar.example.com'
console.dir(req.vhost.length) // => 2
console.dir(req.vhost[0]) // => 'foo'
console.dir(req.vhost[1]) // => 'bar'
}))
var connect = require('connect')
var serveStatic = require('serve-static')
var vhost = require('vhost')
var mailapp = connect()
// add middlewares to mailapp for mail.example.com
// create app to serve static files on subdomain
var staticapp = connect()
staticapp.use(serveStatic('public'))
// create main app
var app = connect()
// add vhost routing to main app for mail
app.use(vhost('mail.example.com', mailapp))
// route static assets for "assets-*" subdomain to get
// around max host connections limit on browsers
app.use(vhost('assets-*.example.com', staticapp))
// add middlewares and main usage to app
app.listen(3000)
var connect = require('connect')
var serveStatic = require('serve-static')
var vhost = require('vhost')
var mainapp = connect()
// add middlewares to mainapp for the main web site
// create app that will server user content from public/{username}/
var userapp = connect()
userapp.use(function (req, res, next) {
var username = req.vhost[0] // username is the "*"
// pretend request was for /{username}/* for file serving
req.originalUrl = req.url
req.url = '/' + username + req.url
next()
})
userapp.use(serveStatic('public'))
// create main app
var app = connect()
// add vhost routing for main app
app.use(vhost('userpages.local', mainapp))
app.use(vhost('www.userpages.local', mainapp))
// listen on all subdomains for user pages
app.use(vhost('*.userpages.local', userapp))
app.listen(3000)
var connect = require('connect')
var http = require('http')
var vhost = require('vhost')
// create main app
var app = connect()
app.use(vhost('mail.example.com', function (req, res) {
// handle req + res belonging to mail.example.com
res.setHeader('Content-Type', 'text/plain')
res.end('hello from mail!')
}))
// an external api server in any framework
var httpServer = http.createServer(function (req, res) {
res.setHeader('Content-Type', 'text/plain')
res.end('hello from the api!')
})
app.use(vhost('api.example.com', function (req, res) {
// handle req + res belonging to api.example.com
// pass the request to a standard Node.js HTTP server
httpServer.emit('request', req, res)
}))
app.listen(3000)