@@ -5,7 +5,7 @@ import languages from '../../lib/languages.js'
55import { allVersions } from '../../lib/all-versions.js'
66import { cacheControlFactory } from '../cache-control.js'
77import catchMiddlewareError from '../catch-middleware-error.js'
8- import { getSearchResults } from './es-search.js'
8+ import { getSearchResults , ELASTICSEARCH_URL } from './es-search.js'
99
1010// Used by the legacy search
1111const versions = new Set ( Object . values ( searchVersions ) )
@@ -51,8 +51,28 @@ function convertLegacyVersionName(version) {
5151 return legacyEnterpriseServerVersions [ version ] || version
5252}
5353
54+ function notConfiguredMiddleware ( req , res , next ) {
55+ if ( ! ELASTICSEARCH_URL ) {
56+ if ( process . env . NODE_ENV === 'production' ) {
57+ // Temporarily, this is OKish. The Docs Engineering team is
58+ // currently working on setting up an Elasticsearch cloud
59+ // instance that we can use. We don't currently have that,
60+ // but this code is running in production. We just don't want
61+ // to unnecessarily throw errors when it's actually a known thing.
62+ return res . status ( 500 ) . send ( 'ELASTICSEARCH_URL not been set up yet' )
63+ }
64+ throw new Error (
65+ 'process.env.ELASTICSEARCH_URL is not set. ' +
66+ "If you're working on this locally, add `ELASTICSEARCH_URL=http://localhost:9200` in your .env file"
67+ )
68+ }
69+
70+ return next ( )
71+ }
72+
5473router . get (
5574 '/legacy' ,
75+ notConfiguredMiddleware ,
5676 catchMiddlewareError ( async function legacySearch ( req , res , next ) {
5777 const { query, version, language, filters, limit : limit_ } = req . query
5878 if ( filters ) {
@@ -196,6 +216,7 @@ const validationMiddleware = (req, res, next) => {
196216router . get (
197217 '/v1' ,
198218 validationMiddleware ,
219+ notConfiguredMiddleware ,
199220 catchMiddlewareError ( async function search ( req , res , next ) {
200221 const { indexName, query, page, size, debug, sort } = req . search
201222 const { meta, hits } = await getSearchResults ( { indexName, query, page, size, debug, sort } )
0 commit comments