Skip to content

Commit

Permalink
🚫🔍 feat: disallow search indexing (danny-avila#1409)
Browse files Browse the repository at this point in the history
* feat: disallow search indexing

* Update index.js

* Update .env.example

* added middleware
  • Loading branch information
berry-13 authored and radityaharya committed Dec 30, 2023
1 parent 2358142 commit fa4dc57
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ MONGO_URI=mongodb://127.0.0.1:27017/LibreChat
DOMAIN_CLIENT=http://localhost:3080
DOMAIN_SERVER=http://localhost:3080

NO_INDEX=true

#===============#
# Debug Logging #
#===============#

DEBUG_LOGGING=true
DEBUG_CONSOLE=false

Expand Down
2 changes: 2 additions & 0 deletions api/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const errorController = require('./controllers/ErrorController');
const configureSocialLogins = require('./socialLogins');
const { connectDb, indexSync } = require('~/lib/db');
const { logger } = require('~/config');
const noIndex = require('./middleware/noIndex');

const Sentry = require('@sentry/node');
const SENTRY_DSN = process.env.SENTRY_DSN;
Expand All @@ -31,6 +32,7 @@ const startServer = async () => {
app.locals.config = paths;

// Middleware
app.use(noIndex);
app.use(errorController);
app.use(express.json({ limit: '3mb' }));
app.use(mongoSanitize());
Expand Down
2 changes: 2 additions & 0 deletions api/server/middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const concurrentLimiter = require('./concurrentLimiter');
const validateMessageReq = require('./validateMessageReq');
const buildEndpointOption = require('./buildEndpointOption');
const validateRegistration = require('./validateRegistration');
const noIndex = require('./noIndex');

module.exports = {
...abortMiddleware,
Expand All @@ -28,4 +29,5 @@ module.exports = {
validateMessageReq,
buildEndpointOption,
validateRegistration,
noIndex,
};
11 changes: 11 additions & 0 deletions api/server/middleware/noIndex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const noIndex = (req, res, next) => {
const shouldNoIndex = process.env.NO_INDEX ? process.env.NO_INDEX === 'true' : true;

if (shouldNoIndex) {
res.setHeader('X-Robots-Tag', 'noindex');
}

next();
};

module.exports = noIndex;

0 comments on commit fa4dc57

Please sign in to comment.