Skip to content

Commit 2ede4aa

Browse files
feat(lapis2-docs): configure LAPIS URL via environment variable
1 parent f98a835 commit 2ede4aa

File tree

7 files changed

+31
-18
lines changed

7 files changed

+31
-18
lines changed

lapis2-docs/src/components/QueryGenerator/QueryGenerator.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import type { Config } from '../../config';
77

88
type Props = {
99
config: Config;
10+
lapisUrl: string;
1011
};
1112

12-
export const QueryGenerator = ({ config }: Props) => {
13+
export const QueryGenerator = ({ config, lapisUrl }: Props) => {
1314
const [step, setStep] = useState(0);
1415
const [queryType, setQueryType] = useState<QueryTypeSelectionState>({
1516
selection: 'aggregatedAll',
@@ -52,7 +53,7 @@ export const QueryGenerator = ({ config }: Props) => {
5253
{step === 0 && <QueryTypeSelection config={config} state={queryType} onStateChange={setQueryType} />}
5354
{step === 1 && <FiltersSelection config={config} filters={filters} onFiltersChange={setFilters} />}
5455
{step === 2 && <>TODO</>}
55-
{step === 3 && <Result queryType={queryType} filters={filters} config={config} />}
56+
{step === 3 && <Result queryType={queryType} filters={filters} config={config} lapisUrl={lapisUrl} />}
5657
</div>
5758

5859
<div className='w-full flex justify-between mt-8'>

lapis2-docs/src/components/QueryGenerator/Result.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type Props = {
1414
queryType: QueryTypeSelectionState;
1515
filters: Filters;
1616
config: Config;
17+
lapisUrl: string;
1718
};
1819

1920
export const Result = (props: Props) => {
@@ -94,17 +95,18 @@ const PythonTab = (props: Props) => {
9495
const propsWithJson: Props = {
9596
...props,
9697
};
97-
const { endpoint, body, resultFields } = constructPostQuery(propsWithJson);
98-
const code = generateNonFastaQuery('', endpoint, body, resultFields);
98+
const { lapisUrl, endpoint, body, resultFields } = constructPostQuery(propsWithJson);
99+
const code = generateNonFastaQuery(lapisUrl, endpoint, body, resultFields);
99100
return <CodeBlock>{code}</CodeBlock>;
100101
};
101102

102-
function constructPostQuery({ queryType, filters, config }: Props): {
103+
function constructPostQuery({ queryType, filters, config, lapisUrl }: Props): {
104+
lapisUrl: string;
103105
endpoint: string;
104106
body: object;
105107
resultFields: ResultField[];
106108
} {
107-
let endpoint = '/sample/';
109+
let endpoint = '/';
108110
const body: any = {};
109111
const resultFields: ResultField[] = [];
110112

@@ -158,7 +160,7 @@ function constructPostQuery({ queryType, filters, config }: Props): {
158160
body[name] = value;
159161
}
160162
}
161-
return { endpoint, body, resultFields };
163+
return { lapisUrl, endpoint, body, resultFields };
162164
}
163165

164166
function mapMetadataTypeToResultFieldType(type: MetadataType): ResultFieldType {

lapis2-docs/src/components/SwaggerUIContainer.astro

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
---
2-
interface Props {
3-
url: string;
4-
}
5-
6-
const { url } = Astro.props;
7-
const test = 'df';
2+
import { getLapisUrl } from '../lapisUrl';
3+
const openApiUrl = getLapisUrl() + '/api-docs';
84
---
95

6+
YAML definition: <a href={openApiUrl}>{openApiUrl}</a>
7+
108
<head>
119
<!-- TODO Don't fetch from external source! -->
1210
<link rel='stylesheet' href='https://unpkg.com/[email protected]/swagger-ui.css' />
1311
</head>
1412

1513
<div class='not-content'>
16-
<swagger-ui-container data-url={url}></swagger-ui-container>
14+
<swagger-ui-container data-url={openApiUrl}></swagger-ui-container>
1715
</div>
1816

1917
<script>

lapis2-docs/src/content/docs/getting-started/generate-your-request.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ description: A step-by-step wizard to help you generate a request
44
---
55

66
import { getConfig } from '../../../config.ts';
7+
import { getLapisUrl } from '../../../lapisUrl.js';
78

89
import { QueryGenerator } from '../../../components/QueryGenerator/QueryGenerator.tsx';
910

10-
<QueryGenerator client:load config={getConfig()} />
11+
<QueryGenerator client:load config={getConfig()} lapisUrl={getLapisUrl()} />

lapis2-docs/src/content/docs/references/open-api-definition.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,4 @@ description: Open API / Swagger
55

66
import SwaggerUIContainer from '../../../components/SwaggerUIContainer.astro';
77

8-
YAML definition: [https://lapis.cov-spectrum.org/openapi/v1.yml](https://lapis.cov-spectrum.org/openapi/v1.yml)
9-
10-
<SwaggerUIContainer url='https://lapis.cov-spectrum.org/openapi/v1.yml' />
8+
<SwaggerUIContainer />

lapis2-docs/src/lapisUrl.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
let lapisUrl: string | null = null;
2+
3+
export function getLapisUrl(): string {
4+
if (lapisUrl === null) {
5+
if (import.meta.env.LAPIS_URL === undefined) {
6+
throw new Error('LAPIS_URL environment variable is not set');
7+
}
8+
lapisUrl = (import.meta.env.LAPIS_URL as string).replace(/\/$/, '');
9+
}
10+
return lapisUrl;
11+
}

lapis2-docs/test-docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ services:
66
- "3000:3000"
77
volumes:
88
- ../siloLapisTests/testData/testDatabaseConfig.yaml:/config/database_config.yaml
9+
environment:
10+
LAPIS_URL: localhost:8080

0 commit comments

Comments
 (0)