diff --git a/Dockerfile b/Dockerfile index 9b691f26d6..efcbf816ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,7 @@ ARG API_URL ARG IMAGE_URL ARG AUTH_URL ARG POSTS_URL +ARG SEARCH_URL # Front-end Web URL, set via ENV in docker or next build ARG WEB_URL @@ -46,6 +47,7 @@ ARG IMAGE_URL ARG AUTH_URL ARG POSTS_URL ARG WEB_URL +ARG SEARCH_URL # Install Production Modules! # Disable postinstall hook in this case since we are being explict with installs @@ -73,6 +75,9 @@ ENV NEXT_PUBLIC_AUTH_URL ${AUTH_URL} ARG POSTS_URL ENV NEXT_PUBLIC_POSTS_URL ${POSTS_URL} +ARG SEARCH_URL +ENV NEXT_PUBLIC_SEARCH_URL ${SEARCH_URL} + ARG WEB_URL ENV NEXT_PUBLIC_WEB_URL ${WEB_URL} diff --git a/docker/production.yml b/docker/production.yml index 6b48a2055a..539826896a 100644 --- a/docker/production.yml +++ b/docker/production.yml @@ -29,6 +29,7 @@ services: - IMAGE_URL=${IMAGE_URL} - AUTH_URL=${AUTH_URL} - POSTS_URL=${POSTS_URL} + - SEARCH_URL=${SEARCH_URL} container_name: 'telescope' restart: unless-stopped environment: @@ -47,6 +48,7 @@ services: - POSTS_URL - API_URL - WEB_URL + - SEARCH_URL - LOG_LEVEL - FEED_URL - FEED_URL_INTERVAL_MS diff --git a/src/api/search/src/routes/query.js b/src/api/search/src/routes/query.js index a8b6d8d374..61747e8071 100644 --- a/src/api/search/src/routes/query.js +++ b/src/api/search/src/routes/query.js @@ -4,12 +4,12 @@ const search = require('../search'); const router = Router(); -router.get('/', validateQuery, async (req, res) => { +router.get('/', validateQuery, async (req, res, next) => { try { const { text, filter, page, perPage } = req.query; res.send(await search(text, filter, page, perPage)); } catch (error) { - next(err); + next(error); } }); diff --git a/src/api/search/src/search.js b/src/api/search/src/search.js index f644f7b98c..b918f3a4e3 100644 --- a/src/api/search/src/search.js +++ b/src/api/search/src/search.js @@ -1,4 +1,4 @@ -const { ELASTIC_MAX_RESULTS_PER_PAGE = 5 } = process.env; +const { ELASTIC_MAX_RESULTS_PER_PAGE = 5, POSTS_URL } = process.env; const { client } = require('./elastic'); const index = 'posts'; @@ -72,7 +72,7 @@ const search = async ( return { results: hits.total.value, - values: hits.hits.map(({ _id }) => ({ id: _id, url: `/posts/${_id}` })), + values: hits.hits.map(({ _id }) => ({ id: _id, url: `${POSTS_URL}/${_id}` })), }; }; diff --git a/src/web/next.config.js b/src/web/next.config.js index 9fd9eadd08..89fd915bf8 100644 --- a/src/web/next.config.js +++ b/src/web/next.config.js @@ -13,7 +13,7 @@ const dotenv = require('dotenv'); const loadApiUrlFromEnv = (envFile) => dotenv.config({ path: envFile }); // ENV Variables we need to forward to next by prefix with NEXT_PUBLIC_* -const envVarsToForward = ['WEB_URL', 'API_URL', 'IMAGE_URL', 'POSTS_URL', 'AUTH_URL']; +const envVarsToForward = ['WEB_URL', 'API_URL', 'IMAGE_URL', 'POSTS_URL', 'AUTH_URL', 'SEARCH_URL']; // Copy an existing ENV Var so it's visible to next: API_URL -> NEXT_PUBLIC_API_URL const forwardToNext = (envVar) => { diff --git a/src/web/src/components/SearchResults.tsx b/src/web/src/components/SearchResults.tsx index d504fba857..a6c73ff4c9 100644 --- a/src/web/src/components/SearchResults.tsx +++ b/src/web/src/components/SearchResults.tsx @@ -2,7 +2,7 @@ import { makeStyles } from '@material-ui/core/styles'; import { useSWRInfinite } from 'swr'; import { Container, Box } from '@material-ui/core'; -import { telescopeUrl } from '../config'; +import { searchServiceUrl } from '../config'; import Timeline from './Posts/Timeline'; import Spinner from './Spinner'; import useSearchValue from '../hooks/use-search-value'; @@ -54,7 +54,7 @@ const SearchResults = () => { const { textParam, filter } = useSearchValue(); const prepareUrl = (index: number) => - `${telescopeUrl}/query?text=${encodeURIComponent(textParam)}&filter=${filter}&page=${index}`; + `${searchServiceUrl}?text=${encodeURIComponent(textParam)}&filter=${filter}&page=${index}`; // We only bother doing the request if we have something to search for. const shouldFetch = () => textParam.length > 0; diff --git a/src/web/src/config.ts b/src/web/src/config.ts index 7dcb719cbd..1a74601b58 100644 --- a/src/web/src/config.ts +++ b/src/web/src/config.ts @@ -11,6 +11,7 @@ const webUrl = process.env.NEXT_PUBLIC_WEB_URL; const imageServiceUrl = process.env.NEXT_PUBLIC_IMAGE_URL; const authServiceUrl = process.env.NEXT_PUBLIC_AUTH_URL; const postsServiceUrl = process.env.NEXT_PUBLIC_POSTS_URL; +const searchServiceUrl = process.env.NEXT_PUBLIC_SEARCH_URL; const title = `Telescope`; const description = `A tool for tracking blogs in orbit around Seneca's open source involvement`; @@ -39,4 +40,5 @@ export { image, imageAlt, postsServiceUrl, + searchServiceUrl, };