Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2014: Adds search service to the front-end #2140

Merged
merged 3 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}

Expand Down
2 changes: 2 additions & 0 deletions docker/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -47,6 +48,7 @@ services:
- POSTS_URL
- API_URL
- WEB_URL
- SEARCH_URL
- LOG_LEVEL
- FEED_URL
- FEED_URL_INTERVAL_MS
Expand Down
4 changes: 2 additions & 2 deletions src/api/search/src/routes/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const search = require('../search');

const router = Router();

router.get('/', validateQuery, async (req, res) => {
router.get('/', validateQuery, async (req, res, next) => {
HyperTHD marked this conversation as resolved.
Show resolved Hide resolved
try {
const { text, filter, page, perPage } = req.query;
res.send(await search(text, filter, page, perPage));
} catch (error) {
next(err);
next(error);
HyperTHD marked this conversation as resolved.
Show resolved Hide resolved
}
});

Expand Down
4 changes: 2 additions & 2 deletions src/api/search/src/search.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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}` })),
};
};

Expand Down
2 changes: 1 addition & 1 deletion src/web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions src/web/src/components/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/web/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down Expand Up @@ -39,4 +40,5 @@ export {
image,
imageAlt,
postsServiceUrl,
searchServiceUrl,
};