fix(frontend): separate server and browser base url (#15)
* fix(frontend): separate server and browser base url * style: format
This commit is contained in:
parent
58605e6af3
commit
2fd9bafaa2
|
@ -1,3 +1,4 @@
|
||||||
VITE_NODE_ENV=development
|
VITE_NODE_ENV=development
|
||||||
VITE_API_ENDPOINT=
|
VITE_SERVER_API_ENDPOINT=
|
||||||
|
VITE_BROWSER_API_ENDPOINT=
|
||||||
VITE_SENTRY_DSN=
|
VITE_SENTRY_DSN=
|
|
@ -8,6 +8,11 @@ WORKDIR /app
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
ENV VITE_NODE_ENV="development"
|
||||||
|
ENV VITE_SERVER_API_ENDPOINT="https://jokesbapak2.reinaldyrafli.com/api/"
|
||||||
|
ENV VITE_BROWSER_API_ENDPOINT="http://api:5000/"
|
||||||
|
ENV VITE_SENTRY_DSN=""
|
||||||
|
|
||||||
RUN npm ci && npm run build && rm -rf node_modules && npm ci --omit=dev
|
RUN npm ci && npm run build && rm -rf node_modules && npm ci --omit=dev
|
||||||
|
|
||||||
EXPOSE ${PORT}
|
EXPOSE ${PORT}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
export default {
|
export default {
|
||||||
API_ENDPOINT: import.meta.env.VITE_API_ENDPOINT,
|
SERVER_API_ENDPOINT: import.meta.env.VITE_SERVER_API_ENDPOINT || 'http://localhost:5000',
|
||||||
SENTRY_DSN: import.meta.env.VITE_SENTRY_DSN,
|
BROWSER_API_ENDPOINT: import.meta.env.VITE_BROWSER_API_ENDPOINT || 'https://jokesbapak2.reinaldyrafli.com',
|
||||||
NODE_ENV: import.meta.env.VITE_NODE_ENV,
|
SENTRY_DSN: import.meta.env.VITE_SENTRY_DSN || '',
|
||||||
|
NODE_ENV: import.meta.env.VITE_NODE_ENV || 'development',
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,7 @@ interface TotalResponse {
|
||||||
export async function load() {
|
export async function load() {
|
||||||
const response = await $fetch<TotalResponse>('total', {
|
const response = await $fetch<TotalResponse>('total', {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
baseURL: env.API_ENDPOINT,
|
baseURL: env.SERVER_API_ENDPOINT,
|
||||||
parseResponse: JSON.parse,
|
parseResponse: JSON.parse,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-1 md:px-6 w-full">
|
<div class="flex-1 md:px-6 w-full">
|
||||||
<div class="max-w-xs mx-auto">
|
<div class="max-w-xs mx-auto">
|
||||||
<img src={env.API_ENDPOINT + `/today`} alt="Sample joke" class="py-6 shadow-2xl" />
|
<img src={env.BROWSER_API_ENDPOINT + `/today`} alt="Sample joke" class="py-6 shadow-2xl" />
|
||||||
</div>
|
</div>
|
||||||
<Codeblock>$ curl -XGET 'https://jokesbapak2.reinaldyrafli.com/api/'</Codeblock>
|
<Codeblock>$ curl -XGET 'https://jokesbapak2.reinaldyrafli.com/api/'</Codeblock>
|
||||||
<p class="text-sm text-center py-4 opacity-70 hover:opacity-100 transition duration-300 ease-in-out">
|
<p class="text-sm text-center py-4 opacity-70 hover:opacity-100 transition duration-300 ease-in-out">
|
||||||
|
|
|
@ -45,22 +45,22 @@
|
||||||
<h2>{$_('api.get.random.title')}</h2>
|
<h2>{$_('api.get.random.title')}</h2>
|
||||||
<p>{$_('api.get.random.body')}</p>
|
<p>{$_('api.get.random.body')}</p>
|
||||||
<Codeblock>
|
<Codeblock>
|
||||||
GET {env.API_ENDPOINT}/
|
GET {env.BROWSER_API_ENDPOINT}/
|
||||||
</Codeblock>
|
</Codeblock>
|
||||||
<h2>{$_('api.get.today.title')}</h2>
|
<h2>{$_('api.get.today.title')}</h2>
|
||||||
<p>{$_('api.get.today.body')}</p>
|
<p>{$_('api.get.today.body')}</p>
|
||||||
<Codeblock>
|
<Codeblock>
|
||||||
GET {env.API_ENDPOINT}/today
|
GET {env.BROWSER_API_ENDPOINT}/today
|
||||||
</Codeblock>
|
</Codeblock>
|
||||||
<h2>{$_('api.get.id.title')}</h2>
|
<h2>{$_('api.get.id.title')}</h2>
|
||||||
<p>{$_('api.get.id.body', { values: { total } })}</p>
|
<p>{$_('api.get.id.body', { values: { total } })}</p>
|
||||||
<Codeblock>
|
<Codeblock>
|
||||||
GET {env.API_ENDPOINT}/id/{id}
|
GET {env.BROWSER_API_ENDPOINT}/id/{id}
|
||||||
</Codeblock>
|
</Codeblock>
|
||||||
<h2>{$_('api.get.total.title')}</h2>
|
<h2>{$_('api.get.total.title')}</h2>
|
||||||
<p>{$_('api.get.total.body')}</p>
|
<p>{$_('api.get.total.body')}</p>
|
||||||
<Codeblock>
|
<Codeblock>
|
||||||
GET {env.API_ENDPOINT}/total
|
GET {env.BROWSER_API_ENDPOINT}/total
|
||||||
</Codeblock>
|
</Codeblock>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Codeblock from '../../components/codeblock.svelte';
|
import Codeblock from '../../components/codeblock.svelte';
|
||||||
import { _ } from 'svelte-i18n';
|
import { _ } from 'svelte-i18n';
|
||||||
|
import env from '$lib/env';
|
||||||
// This page is meant to guide people on how to use the API.
|
// This page is meant to guide people on how to use the API.
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -25,14 +26,14 @@
|
||||||
|
|
||||||
<section class="guide_page">
|
<section class="guide_page">
|
||||||
<h2>{$_('guide.direct.1')} <code><img></code> {$_('guide.direct.2')}</h2>
|
<h2>{$_('guide.direct.1')} <code><img></code> {$_('guide.direct.2')}</h2>
|
||||||
<Codeblock><img src="https://jokesbapak2.reinaldyrafli.com/api/" /></Codeblock>
|
<Codeblock><img src="{env.BROWSER_API_ENDPOINT}/" /></Codeblock>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="guide_page">
|
<section class="guide_page">
|
||||||
<h2>{$_('guide.fetch.1')}</h2>
|
<h2>{$_('guide.fetch.1')}</h2>
|
||||||
<p>{$_('guide.fetch.2')}</p>
|
<p>{$_('guide.fetch.2')}</p>
|
||||||
<Codeblock>
|
<Codeblock>
|
||||||
const response = await fetch("https://jokesbapak2.reinaldyrafli.com/api/");<br />
|
const response = await fetch("{env.BROWSER_API_ENDPOINT}/");<br />
|
||||||
<br />
|
<br />
|
||||||
if (!response.ok) {<br />
|
if (!response.ok) {<br />
|
||||||
// {$_('guide.fetch.3')}<br />
|
// {$_('guide.fetch.3')}<br />
|
||||||
|
|
Loading…
Reference in New Issue