diff --git a/package.json b/package.json index 443f75f1b..75a1948f5 100644 --- a/package.json +++ b/package.json @@ -110,7 +110,7 @@ "scripts": { "start": "cross-env PORT=3001 craco start", "start:test": "cross-env REACT_APP_TEST_MODE=true yarn start", - "start:for-real-backend": "cross-env REACT_APP_BACKEND_BASE_URL=http://localhost:3000 yarn start", + "start:for-real-backend": "cross-env REACT_APP_BACKEND_BASE_URL=http://localhost:3000/ yarn start", "serve:build": "http-server build/ -s -p 3001 -P \"http://localhost:3001?\"", "build:test": "cross-env REACT_APP_TEST_MODE=true craco build", "build:mock": "cross-env craco build", diff --git a/src/api/auth/index.ts b/src/api/auth/index.ts index 7228ae302..e02419509 100644 --- a/src/api/auth/index.ts +++ b/src/api/auth/index.ts @@ -10,7 +10,7 @@ import { defaultFetchConfig, expectResponseCode, getApiUrl } from '../utils' export const INTERACTIVE_LOGIN_METHODS = ['internal', 'ldap', 'openid'] export const doInternalLogin = async (username: string, password: string): Promise => { - const response = await fetch(getApiUrl() + '/auth/internal', { + const response = await fetch(getApiUrl() + 'auth/internal', { ...defaultFetchConfig, method: 'POST', body: JSON.stringify({ @@ -23,7 +23,7 @@ export const doInternalLogin = async (username: string, password: string): Promi } export const doInternalRegister = async (username: string, password: string): Promise => { - const response = await fetch(getApiUrl() + '/auth/register', { + const response = await fetch(getApiUrl() + 'auth/register', { ...defaultFetchConfig, method: 'POST', body: JSON.stringify({ @@ -40,7 +40,7 @@ export const doInternalRegister = async (username: string, password: string): Pr } export const doLdapLogin = async (username: string, password: string): Promise => { - const response = await fetch(getApiUrl() + '/auth/ldap', { + const response = await fetch(getApiUrl() + 'auth/ldap', { ...defaultFetchConfig, method: 'POST', body: JSON.stringify({ @@ -53,7 +53,7 @@ export const doLdapLogin = async (username: string, password: string): Promise => { - const response = await fetch(getApiUrl() + '/auth/openid', { + const response = await fetch(getApiUrl() + 'auth/openid', { ...defaultFetchConfig, method: 'POST', body: JSON.stringify({ diff --git a/src/api/config/index.ts b/src/api/config/index.ts index 9feb930ae..a64c34258 100644 --- a/src/api/config/index.ts +++ b/src/api/config/index.ts @@ -8,7 +8,7 @@ import { defaultFetchConfig, expectResponseCode, getApiUrl } from '../utils' import { Config } from './types' export const getConfig = async (): Promise => { - const response = await fetch(getApiUrl() + '/config', { + const response = await fetch(getApiUrl() + 'config', { ...defaultFetchConfig }) expectResponseCode(response) diff --git a/src/api/history/index.ts b/src/api/history/index.ts index 77d521dc9..a3372f10e 100644 --- a/src/api/history/index.ts +++ b/src/api/history/index.ts @@ -8,13 +8,13 @@ import { defaultFetchConfig, expectResponseCode, getApiUrl } from '../utils' import { HistoryEntryDto, HistoryEntryPutDto, HistoryEntryUpdateDto } from './types' export const getHistory = async (): Promise => { - const response = await fetch(getApiUrl() + '/me/history') + const response = await fetch(getApiUrl() + 'me/history') expectResponseCode(response) return await response.json() as Promise } export const postHistory = async (entries: HistoryEntryPutDto[]): Promise => { - const response = await fetch(getApiUrl() + '/me/history', { + const response = await fetch(getApiUrl() + 'me/history', { ...defaultFetchConfig, method: 'POST', body: JSON.stringify(entries) @@ -23,7 +23,7 @@ export const postHistory = async (entries: HistoryEntryPutDto[]): Promise } export const updateHistoryEntryPinStatus = async (noteId: string, entry: HistoryEntryUpdateDto): Promise => { - const response = await fetch(getApiUrl() + '/me/history/' + noteId, { + const response = await fetch(getApiUrl() + 'me/history/' + noteId, { ...defaultFetchConfig, method: 'PUT', body: JSON.stringify(entry) @@ -32,7 +32,7 @@ export const updateHistoryEntryPinStatus = async (noteId: string, entry: History } export const deleteHistoryEntry = async (noteId: string): Promise => { - const response = await fetch(getApiUrl() + '/me/history/' + noteId, { + const response = await fetch(getApiUrl() + 'me/history/' + noteId, { ...defaultFetchConfig, method: 'DELETE' }) @@ -40,7 +40,7 @@ export const deleteHistoryEntry = async (noteId: string): Promise => { } export const deleteHistory = async (): Promise => { - const response = await fetch(getApiUrl() + '/me/history', { + const response = await fetch(getApiUrl() + 'me/history', { ...defaultFetchConfig, method: 'DELETE' }) diff --git a/src/api/me/index.ts b/src/api/me/index.ts index 1488677e6..a9109d97a 100644 --- a/src/api/me/index.ts +++ b/src/api/me/index.ts @@ -9,7 +9,7 @@ import { defaultFetchConfig, expectResponseCode, getApiUrl } from '../utils' import { isMockMode } from '../../utils/test-modes' export const getMe = async (): Promise => { - const response = await fetch(getApiUrl() + `/me${ isMockMode() ? '-get' : '' }`, { + const response = await fetch(getApiUrl() + `me${ isMockMode() ? '-get' : '' }`, { ...defaultFetchConfig }) expectResponseCode(response) @@ -17,7 +17,7 @@ export const getMe = async (): Promise => { } export const updateDisplayName = async (displayName: string): Promise => { - const response = await fetch(getApiUrl() + '/me', { + const response = await fetch(getApiUrl() + 'me', { ...defaultFetchConfig, method: 'POST', body: JSON.stringify({ @@ -29,7 +29,7 @@ export const updateDisplayName = async (displayName: string): Promise => { } export const changePassword = async (oldPassword: string, newPassword: string): Promise => { - const response = await fetch(getApiUrl() + '/me/password', { + const response = await fetch(getApiUrl() + 'me/password', { ...defaultFetchConfig, method: 'POST', body: JSON.stringify({ @@ -42,7 +42,7 @@ export const changePassword = async (oldPassword: string, newPassword: string): } export const deleteUser = async (): Promise => { - const response = await fetch(getApiUrl() + '/me', { + const response = await fetch(getApiUrl() + 'me', { ...defaultFetchConfig, method: 'DELETE' }) diff --git a/src/api/media/index.ts b/src/api/media/index.ts index 5a2cc5fe0..107ff37a7 100644 --- a/src/api/media/index.ts +++ b/src/api/media/index.ts @@ -8,7 +8,7 @@ import { ImageProxyResponse } from '../../components/markdown-renderer/replace-c import { defaultFetchConfig, expectResponseCode, getApiUrl } from '../utils' export const getProxiedUrl = async (imageUrl: string): Promise => { - const response = await fetch(getApiUrl() + '/media/proxy', { + const response = await fetch(getApiUrl() + 'media/proxy', { ...defaultFetchConfig, method: 'POST', body: JSON.stringify({ @@ -24,7 +24,7 @@ export interface UploadedMedia { } export const uploadFile = async (noteId: string, contentType: string, media: Blob): Promise => { - const response = await fetch(getApiUrl() + '/media/upload', { + const response = await fetch(getApiUrl() + 'media/upload', { ...defaultFetchConfig, headers: { 'Content-Type': contentType, diff --git a/src/api/notes/index.ts b/src/api/notes/index.ts index 09acad7ee..d42523ed7 100644 --- a/src/api/notes/index.ts +++ b/src/api/notes/index.ts @@ -11,7 +11,7 @@ import { isMockMode } from '../../utils/test-modes' export const getNote = async (noteId: string): Promise => { // The "-get" suffix is necessary, because in our mock api (filesystem) the note id might already be a folder. // TODO: [mrdrogdrog] replace -get with actual api route as soon as api backend is ready. - const response = await fetch(getApiUrl() + `/notes/${ noteId }${ isMockMode() ? '-get' : '' }`, { + const response = await fetch(getApiUrl() + `notes/${ noteId }${ isMockMode() ? '-get' : '' }`, { ...defaultFetchConfig }) expectResponseCode(response) @@ -19,7 +19,7 @@ export const getNote = async (noteId: string): Promise => { } export const deleteNote = async (noteId: string): Promise => { - const response = await fetch(getApiUrl() + `/notes/${ noteId }`, { + const response = await fetch(getApiUrl() + `notes/${ noteId }`, { ...defaultFetchConfig, method: 'DELETE' }) diff --git a/src/api/revisions/index.ts b/src/api/revisions/index.ts index a482b67f0..964845ca7 100644 --- a/src/api/revisions/index.ts +++ b/src/api/revisions/index.ts @@ -15,7 +15,7 @@ export const getRevision = async (noteId: string, timestamp: number): Promise => { // TODO Change 'revisions-list' to 'revisions' as soon as the backend is ready to serve some data! - const response = await fetch(getApiUrl() + `/notes/${ noteId }/revisions-list`, { + const response = await fetch(getApiUrl() + `notes/${ noteId }/revisions-list`, { ...defaultFetchConfig }) expectResponseCode(response) diff --git a/src/api/tokens/index.ts b/src/api/tokens/index.ts index ee004e0ef..f0ce8b632 100644 --- a/src/api/tokens/index.ts +++ b/src/api/tokens/index.ts @@ -8,7 +8,7 @@ import { defaultFetchConfig, expectResponseCode, getApiUrl } from '../utils' import { AccessToken, AccessTokenSecret } from './types' export const getAccessTokenList = async (): Promise => { - const response = await fetch(`${ getApiUrl() }/tokens`, { + const response = await fetch(`${ getApiUrl() }tokens`, { ...defaultFetchConfig }) expectResponseCode(response) @@ -16,7 +16,7 @@ export const getAccessTokenList = async (): Promise => { } export const postNewAccessToken = async (label: string): Promise => { - const response = await fetch(`${ getApiUrl() }/tokens`, { + const response = await fetch(`${ getApiUrl() }tokens`, { ...defaultFetchConfig, method: 'POST', body: label @@ -26,7 +26,7 @@ export const postNewAccessToken = async (label: string): Promise => { - const response = await fetch(`${ getApiUrl() }/tokens/${ timestamp }`, { + const response = await fetch(`${ getApiUrl() }tokens/${ timestamp }`, { ...defaultFetchConfig, method: 'DELETE' }) diff --git a/src/components/application-loader/initializers/fetch-and-set-banner.ts b/src/components/application-loader/initializers/fetch-and-set-banner.ts index 462e6deb4..54b8ea358 100644 --- a/src/components/application-loader/initializers/fetch-and-set-banner.ts +++ b/src/components/application-loader/initializers/fetch-and-set-banner.ts @@ -11,7 +11,7 @@ export const BANNER_LOCAL_STORAGE_KEY = 'banner.lastModified' export const fetchAndSetBanner = async (customizeAssetsUrl: string): Promise => { const cachedLastModified = window.localStorage.getItem(BANNER_LOCAL_STORAGE_KEY) - const bannerUrl = `${ customizeAssetsUrl }/banner.txt` + const bannerUrl = `${ customizeAssetsUrl }banner.txt` if (cachedLastModified) { const response = await fetch(bannerUrl, { diff --git a/src/components/application-loader/initializers/i18n.ts b/src/components/application-loader/initializers/i18n.ts index 952fc4987..e043ce762 100644 --- a/src/components/application-loader/initializers/i18n.ts +++ b/src/components/application-loader/initializers/i18n.ts @@ -19,7 +19,7 @@ export const setUpI18n = async (frontendAssetsUrl: string): Promise => { fallbackLng: 'en', debug: process.env.NODE_ENV !== 'production', backend: { - loadPath: `${ frontendAssetsUrl }/locales/{{lng}}.json` + loadPath: `${ frontendAssetsUrl }locales/{{lng}}.json` }, interpolation: { diff --git a/src/components/application-loader/initializers/index.ts b/src/components/application-loader/initializers/index.ts index c72253f20..958b63373 100644 --- a/src/components/application-loader/initializers/index.ts +++ b/src/components/application-loader/initializers/index.ts @@ -26,7 +26,7 @@ export interface InitTask { export const createSetUpTaskList = (frontendAssetsUrl: string, customizeAssetsUrl: string, backendBaseUrl: string): InitTask[] => { setApiUrl({ - apiUrl: `${ backendBaseUrl }/api/private` + apiUrl: `${ backendBaseUrl }api/private/` }) return [{ diff --git a/src/components/intro-page/requests.ts b/src/components/intro-page/requests.ts index ef27e4d3b..fa3f7dc89 100644 --- a/src/components/intro-page/requests.ts +++ b/src/components/intro-page/requests.ts @@ -7,7 +7,7 @@ import { defaultFetchConfig, expectResponseCode } from '../../api/utils' export const fetchFrontPageContent = async (customizeAssetsUrl: string): Promise => { - const response = await fetch(customizeAssetsUrl + '/intro.md', { + const response = await fetch(customizeAssetsUrl + 'intro.md', { ...defaultFetchConfig, method: 'GET' }) diff --git a/src/components/landing-layout/navigation/sign-in-button.tsx b/src/components/landing-layout/navigation/sign-in-button.tsx index 3d6909f5f..d02b4ef6c 100644 --- a/src/components/landing-layout/navigation/sign-in-button.tsx +++ b/src/components/landing-layout/navigation/sign-in-button.tsx @@ -30,7 +30,7 @@ export const SignInButton: React.FC = ({ variant, ...props }) const activeOneClickProviders = activeProviders.filter(entry => !INTERACTIVE_LOGIN_METHODS.includes(entry)) if (activeProviders.length === 1 && activeOneClickProviders.length === 1) { - return `${ getApiUrl() }/auth/${ activeOneClickProviders[0] }` + return `${ getApiUrl() }auth/${ activeOneClickProviders[0] }` } return '/login' }, [authProviders]) diff --git a/src/components/profile-page/settings/profile-account-management.tsx b/src/components/profile-page/settings/profile-account-management.tsx index 5f9045486..3ea3cddd8 100644 --- a/src/components/profile-page/settings/profile-account-management.tsx +++ b/src/components/profile-page/settings/profile-account-management.tsx @@ -63,7 +63,7 @@ export const ProfileAccountManagement: React.FC = () => { - diff --git a/src/hooks/common/use-backend-base-url.ts b/src/hooks/common/use-backend-base-url.ts index 11f0487b5..4156b68df 100644 --- a/src/hooks/common/use-backend-base-url.ts +++ b/src/hooks/common/use-backend-base-url.ts @@ -5,5 +5,5 @@ */ export const useBackendBaseUrl = (): string => { - return process.env.REACT_APP_BACKEND_BASE_URL ?? '/mock-backend' + return process.env.REACT_APP_BACKEND_BASE_URL ?? '/mock-backend/' } diff --git a/src/hooks/common/use-customize-assets-url.ts b/src/hooks/common/use-customize-assets-url.ts index 84aca61d5..b1ab52ad7 100644 --- a/src/hooks/common/use-customize-assets-url.ts +++ b/src/hooks/common/use-customize-assets-url.ts @@ -8,5 +8,5 @@ import { useBackendBaseUrl } from './use-backend-base-url' export const useCustomizeAssetsUrl = (): string => { const backendBaseUrl = useBackendBaseUrl() - return (process.env.REACT_APP_CUSTOMIZE_ASSETS_URL || `${ backendBaseUrl }/public`) + return (process.env.REACT_APP_CUSTOMIZE_ASSETS_URL || `${ backendBaseUrl }public/`) } diff --git a/src/hooks/common/use-frontend-base-url.ts b/src/hooks/common/use-frontend-base-url.ts index 030e6f7cb..0ac692b58 100644 --- a/src/hooks/common/use-frontend-base-url.ts +++ b/src/hooks/common/use-frontend-base-url.ts @@ -11,5 +11,5 @@ export const useFrontendBaseUrl = (): string => { const location = window.location const cleanedPathName = location.pathname.replace(pathname, '') - return `${ location.protocol }//${ location.host }${ cleanedPathName }` + return `${ location.protocol }//${ location.host }${ cleanedPathName }/` }