Skip to content

Commit

Permalink
Host Specificity Support
Browse files Browse the repository at this point in the history
  • Loading branch information
pmh-only committed Apr 19, 2020
1 parent 7068ec5 commit 18dfcc7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
23 changes: 18 additions & 5 deletions class/Rapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,41 @@ let appl

/** @class */
class Rapp {
constructor (root) {
constructor (root, host) {
this.root = root
this.host = host
}

/** @param {reqandres} cb */
get (path, cb) {
appl.get(this.root + path, cb)
appl.get(this.root + path, (req, res) => {
if (!this.host) return cb(req, res)
if (this.host === req.hostname) return cb(req, res)
})
}

/** @param {reqandres} cb */
put (path, cb) {
appl.put(this.root + path, cb)
appl.put(this.root + path, (req, res) => {
if (!this.host) return cb(req, res)
if (this.host === req.hostname) return cb(req, res)
})
}

/** @param {reqandres} cb */
post (path, cb) {
appl.post(this.root + path, cb)
appl.post(this.root + path, (req, res) => {
if (!this.host) return cb(req, res)
if (this.host === req.hostname) return cb(req, res)
})
}

/** @param {reqandres} cb */
all (path, cb) {
appl.all(this.root + path, cb)
appl.all(this.root + path, (req, res) => {
if (!this.host) return cb(req, res)
if (this.host === req.baseUrl) return cb(req, res)
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ readdir(path + '/router', (err, routers) => {
})
}

const rapp = new Rapp(router._root)
const rapp = new Rapp(router._root, router._host)
router.ready(rapp, router._socket ? { ws: socket, wss: ssocket } : undefined)
})
})
2 changes: 1 addition & 1 deletion router/example/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = { _root: '/example', _socket: false, _cors: true, _parser: [], ready }
module.exports = { _root: '/example', _socket: false, _cors: true, _host: 'direct.trinets.xyz', _parser: [], ready }

function ready (app) {
console.log('example is loaded')
Expand Down
2 changes: 1 addition & 1 deletion router/main
Submodule main updated 1 files
+0 −8 package.json

0 comments on commit 18dfcc7

Please sign in to comment.