Answer the question
In order to leave comments, you need to log in
How to allow site access to specific ip on node express server?
Under this I found the module express-ipfilter .
the description says:
// Init dependencies
var express = require('express')
, ipfilter = require('express-ipfilter')
, app = express.createServer()
;
// Whitelist the following IPs
var ips = ['127.0.0.1'];
// Create the server
app.use(ipfilter(ips, {mode: 'allow'}));
app.listen(3000);
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var routes = require('./routes/index');
var users = require('./routes/users');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views/'));
app.set('view engine', 'ejs');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', routes);
app.use('/users', users);
…..
var app = require('../app');
var debug = require('debug')('dataBase:server');
var http = require('http');
/**
* Get port from environment and store in Express.
*/
var serverIP = '10.10.12.120'
var port = normalizePort(process.env.PORT || '3007');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port,serverIP);
server.on('error', onError);
server.on('listening', onListening);
…….
Answer the question
In order to leave comments, you need to log in
This can be done anywhere where there is access to the application instance (in the code, this is the `app` variable).
It is better to connect all middleware in one place, i.e. in your case it is `app.js`
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question