Skip to content

Commit

Permalink
Add robots.txt to avoid indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarvelle committed Oct 16, 2024
1 parent e38c077 commit 954f9d1
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,26 @@ import compression from 'compression';
import cors from 'cors';
import config from './config';
import { fetchApis } from './api/kongApi';
import { apiListTemplate, htmlErrorTemplate, index } from './utils/htmlTemplates';
import {
apiListTemplate,
htmlErrorTemplate,
index,
} from './utils/htmlTemplates';
import { getAppropriateErrorResponse } from './utils/errorHelpers';

/* eslint arrow-parens: 0 */

const app = express();
const path = require('path');
const pathToSwaggerUi = require('swagger-ui-dist').absolutePath();

app.use(compression());
app.use(cors({
origin: true,
credentials: true,
}));
app.use(
cors({
origin: true,
credentials: true,
}),
);
app.use('/static', express.static(path.join(__dirname, 'static')));
app.use('/swagger-ui-dist', express.static(pathToSwaggerUi));

Expand All @@ -39,9 +47,17 @@ app.get('/advanced/swagger', (req, res) => {
const withTemplate = (swaggerPath, req, res) => {
fetchApis()
.then((routes) => {
res.send(apiListTemplate(swaggerPath, routes.filter(el => el.paths.find(apiPath => config.apiDocPath.test(apiPath)))));
res.send(
apiListTemplate(
swaggerPath,
routes.filter((el) =>
el.paths.find((apiPath) => config.apiDocPath.test(apiPath)),
),
),
);
res.end();
}).catch((error) => {
})
.catch((error) => {
const response = getAppropriateErrorResponse(error, config.isProduction);
res.status(response.status).send(htmlErrorTemplate(response));
});
Expand All @@ -59,6 +75,11 @@ app.get('/health', (req, res) => {
res.status(200).json({ status: 200, text: 'Health check ok' });
});

app.get('/robots.txt', (_, res) => {
res.type('text/plain');
res.send('User-agent: *\nAllow: /\n Disallow: /*/');
});

app.get('*', (req, res) => {
res.status(404).json({ status: 404, text: 'Not found' });
});
Expand Down

0 comments on commit 954f9d1

Please sign in to comment.