Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/digitalcortex/feathers-express-ip
Expose requester's IP address to your Feathers services
https://github.com/digitalcortex/feathers-express-ip
express-js feathers feathers-js
Last synced: 5 days ago
JSON representation
Expose requester's IP address to your Feathers services
- Host: GitHub
- URL: https://github.com/digitalcortex/feathers-express-ip
- Owner: digitalcortex
- License: mit
- Created: 2020-06-07T19:10:51.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-12-14T01:17:52.000Z (about 2 years ago)
- Last Synced: 2024-12-12T14:48:31.461Z (10 days ago)
- Topics: express-js, feathers, feathers-js
- Language: TypeScript
- Homepage:
- Size: 173 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Expose requester's IP address to your Feathers services
With feathers-express-ip you can make your own solution for:
- Rate limiting per IP address
- Tracing the request by IP## Installation
```
npm install feathers-express-ip --save
``````
yarn add feathers-express-ip
```## Example usage
Import package
```typescript
// Typescript
import { feathersIp, feathersIpSocketIO } from 'feathers-express-ip';// Javascript
const { feathersIp, feathersIpSocketIO } = require('feathers-express-ip');
```For working with socket connections:
```typescript
// Replace following line in src/app.ts:
app.configure(socketio());// With following code:
app.configure(socketio(function (io) {
feathersIpSocketIO(io, 'ip');
}));
```For working with standard HTTP requests:
```typescript
// After following line in src/app.ts:
app.configure(express.rest());// Add following line:
app.use(feathersIp('ip'));
```Read provided IP address in Feathers hook:
```typescript
(context: HookContext) => {
console.log(context.params.ip);
}
```## Using with reverse proxy
Reverse proxies not only hide IP address of your app from the user, they also hide the user's IP address from the app.
If you want to get user's IP address while using reverse proxy such as Nginx, you will need configure your Nginx server accordingly.[Read explanation on Nginx website](https://www.nginx.com/resources/wiki/start/topics/examples/forwarded/)
In short, you can add following code in your Nginx config to set the headers:
```
proxy_pass_header Set-Cookie;proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
```