https://github.com/coderaiser/node-proxy-user
proxy requests according to username
https://github.com/coderaiser/node-proxy-user
Last synced: 9 months ago
JSON representation
proxy requests according to username
- Host: GitHub
- URL: https://github.com/coderaiser/node-proxy-user
- Owner: coderaiser
- License: mit
- Created: 2016-02-09T17:36:28.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2018-11-15T13:22:11.000Z (over 7 years ago)
- Last Synced: 2025-05-17T21:46:54.621Z (11 months ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog
- License: LICENSE
Awesome Lists containing this project
README
# proxy-user
Proxy requests according to username.
## Install
`npm i proxy-user --save`
## API
```js
const proxyUser = require('proxy-user');
```
### proxyUser.web(options)
Proxy http requests.
`options` could contain:
- `logout` function on `/[username]/logout`
- `port` to redirect to
- `user` data (`username`, `password`)
- `target` url to redirect to
```js
proxyUser.web({
logout: req => console.log('logout'),
port: 80, // default
target: 'localhost',// default
user: {
username: 'coderaiser',
password: 'hello'
}
});
```
### proxyUser.web(options)
Proxy socket requests.
`options` could contain:
- `port` to redirect to
- `user` data (`username`, `password`)
- `target` url to redirect to
```js
proxy.socket({
port: 80 // default
target: 'localhost',// default
})
```
## Example
`proxy-user` could be used as [express](http://expressjs.com) middleware.
```js
const http = require('http');
const app = require('express')();
const server = http.createServer(app);
const PORT = 31337;
const socket = proxy.socket()
.on('error', (error) => {
console.error(error.message);
})
server.on('upgrade', socket);
app.use(proxyUser.web({
username: 'coderaiser',
password: 'hello'
});
server.listen(PORT, () => {
console.log('url: http://%s:%d', 'localhost', PORT);
});
```
## License
MIT