Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
You need to write a middleware to filter by country,
an example using the ilocate library to get the country of the request
const express = require('express');
const app = express();
const iplocate = require('iplocate');
app.use(iplocate);
// middleware for filtering by country
app.use(function (req, res, next) {
// some error
if ( req.locationError ) {
// handle error
}
if ( req.location.country_code !== 'RU' ){
return res.send("request available only from russia")
}
next();
});
app
.get('/', (req, res) => {
res.send('success');
})
app.listen(3000, function () {
console.log('app listening on port 3000!');
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question