Skip to content

Commit e2d0980

Browse files
committed
OCPBUGS-80939: Add robots.txt policy to console
also simplify locales copy/paste into a glob (which also prevents the locales OWNERS files from being bundled)
1 parent 0623c9b commit e2d0980

File tree

3 files changed

+18
-25
lines changed

3 files changed

+18
-25
lines changed

frontend/public/robots.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
User-agent: *
2+
Disallow: /

frontend/webpack.config.ts

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin
33
import * as HtmlWebpackPlugin from 'html-webpack-plugin';
44
import * as _ from 'lodash';
55
import * as MiniCssExtractPlugin from 'mini-css-extract-plugin';
6+
import * as CopyWebpackPlugin from 'copy-webpack-plugin';
67
import * as path from 'path';
78
import * as webpack from 'webpack';
89
import { WebpackSharedObject, WebpackSharedConfig } from '@openshift/dynamic-plugin-sdk-webpack';
@@ -24,7 +25,6 @@ interface Configuration extends webpack.Configuration {
2425
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
2526
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
2627
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
27-
const CopyWebpackPlugin = require('copy-webpack-plugin');
2828
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
2929

3030
const NODE_ENV = process.env.NODE_ENV || 'development';
@@ -288,31 +288,16 @@ const config: Configuration = {
288288
}),
289289
new CopyWebpackPlugin({
290290
patterns: [
291-
{ from: path.resolve(__dirname, './public/locales'), to: 'locales' },
292-
{ from: path.resolve(__dirname, './packages/console-shared/locales'), to: 'locales' },
293-
{ from: path.resolve(__dirname, './packages/console-app/locales'), to: 'locales' },
291+
{ from: path.resolve(__dirname, './public/robots.txt'), to: 'robots.txt' },
294292
{
295-
from: path.resolve(__dirname, './packages/operator-lifecycle-manager/locales'),
296-
to: 'locales',
297-
},
298-
{
299-
from: path.resolve(__dirname, './packages/operator-lifecycle-manager-v1/locales'),
300-
to: 'locales',
301-
},
302-
{ from: path.resolve(__dirname, './packages/dev-console/locales'), to: 'locales' },
303-
{ from: path.resolve(__dirname, './packages/knative-plugin/locales'), to: 'locales' },
304-
{ from: path.resolve(__dirname, './packages/container-security/locales'), to: 'locales' },
305-
{ from: path.resolve(__dirname, './packages/shipwright-plugin/locales'), to: 'locales' },
306-
{ from: path.resolve(__dirname, './packages/webterminal-plugin/locales'), to: 'locales' },
307-
{ from: path.resolve(__dirname, './packages/topology/locales'), to: 'locales' },
308-
{ from: path.resolve(__dirname, './packages/helm-plugin/locales'), to: 'locales' },
309-
{ from: path.resolve(__dirname, './packages/git-service/locales'), to: 'locales' },
310-
{ from: path.resolve(__dirname, './packages/metal3-plugin/locales'), to: 'locales' },
311-
{ from: path.resolve(__dirname, './packages/vsphere-plugin/locales'), to: 'locales' },
312-
{ from: path.resolve(__dirname, './packages/insights-plugin/locales'), to: 'locales' },
313-
{
314-
from: path.resolve(__dirname, './packages/console-telemetry-plugin/locales'),
315-
to: 'locales',
293+
from: './{packages/*,public}/locales',
294+
// Flat locales directory structure: /static/locales/{en,fr,...}/{namespace}.json
295+
to: ({ absoluteFilename }) => {
296+
const segments = absoluteFilename.split(path.sep);
297+
return segments.slice(segments.lastIndexOf('locales')).join(path.sep);
298+
},
299+
context: path.resolve(__dirname),
300+
filter: (p) => path.extname(p) === '.json',
316301
},
317302
],
318303
}),

pkg/server/server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ func (s *Server) HTTPHandler() (http.Handler, error) {
335335
staticHandler := http.StripPrefix(proxy.SingleJoiningSlash(s.BaseURL.Path, "/static/"), disableDirectoryListing(http.FileServer(http.Dir(s.PublicDir))))
336336
handle("/static/", middleware.WithGZIPEncoding(middleware.WithSecurityHeaders(staticHandler)))
337337

338+
// Register robots.txt at the origin root so crawlers can find it at /robots.txt
339+
// regardless of s.BaseURL.Path (e.g., /console/).
340+
mux.HandleFunc("/robots.txt", func(w http.ResponseWriter, r *http.Request) {
341+
http.ServeFile(w, r, path.Join(s.PublicDir, "robots.txt"))
342+
})
343+
338344
if s.CustomLogoFiles != nil {
339345
handleFunc(customLogoEndpoint, func(w http.ResponseWriter, r *http.Request) {
340346
serverconfig.CustomLogosHandler(w, r, s.CustomLogoFiles, s.CustomFaviconFiles)

0 commit comments

Comments
 (0)