mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 02:05:21 -04:00
rework how the frontend is started (#361)
renamed frontend-config to api-url renamed backend-config to config removed api call to set frontend-config as the frontend either know where the backend is as it is delivered by it or get's this information via the enviroment variable REACT_APP_BACKEND always start the client on Port 3001 as the backend will run on 3000 during development. changed the port on multiple occasions to accommodate for this added package.json script 'start:dev' changed README to better explain how to run backend and frontend side-by-side
This commit is contained in:
parent
287d2e2729
commit
d0fc96b929
42 changed files with 173 additions and 182 deletions
|
@ -1,8 +1,8 @@
|
|||
import { expectResponseCode, getBackendUrl } from '../utils/apiUtils'
|
||||
import { expectResponseCode, getApiUrl } from '../utils/apiUtils'
|
||||
import { defaultFetchConfig } from './default'
|
||||
|
||||
export const doEmailLogin = async (email: string, password: string): Promise<void> => {
|
||||
const response = await fetch(getBackendUrl() + '/auth/email', {
|
||||
const response = await fetch(getApiUrl() + '/auth/email', {
|
||||
...defaultFetchConfig,
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
|
@ -15,7 +15,7 @@ export const doEmailLogin = async (email: string, password: string): Promise<voi
|
|||
}
|
||||
|
||||
export const doLdapLogin = async (username: string, password: string): Promise<void> => {
|
||||
const response = await fetch(getBackendUrl() + '/auth/ldap', {
|
||||
const response = await fetch(getApiUrl() + '/auth/ldap', {
|
||||
...defaultFetchConfig,
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
|
@ -28,7 +28,7 @@ export const doLdapLogin = async (username: string, password: string): Promise<v
|
|||
}
|
||||
|
||||
export const doOpenIdLogin = async (openId: string): Promise<void> => {
|
||||
const response = await fetch(getBackendUrl() + '/auth/openid', {
|
||||
const response = await fetch(getApiUrl() + '/auth/openid', {
|
||||
...defaultFetchConfig,
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
import { expectResponseCode, getBackendUrl } from '../../utils/apiUtils'
|
||||
import { BackendConfig } from './types'
|
||||
|
||||
export const getBackendConfig = async (): Promise<BackendConfig> => {
|
||||
const response = await fetch(getBackendUrl() + '/config')
|
||||
expectResponseCode(response)
|
||||
return await response.json() as Promise<BackendConfig>
|
||||
}
|
11
src/api/config/index.ts
Normal file
11
src/api/config/index.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
import { expectResponseCode, getApiUrl } from '../../utils/apiUtils'
|
||||
import { defaultFetchConfig } from '../default'
|
||||
import { Config } from './types'
|
||||
|
||||
export const getConfig = async (): Promise<Config> => {
|
||||
const response = await fetch(getApiUrl() + '/config', {
|
||||
...defaultFetchConfig
|
||||
})
|
||||
expectResponseCode(response)
|
||||
return await response.json() as Promise<Config>
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
export interface BackendConfig {
|
||||
export interface Config {
|
||||
allowAnonymous: boolean,
|
||||
authProviders: AuthProvidersState,
|
||||
branding: BrandingConfig,
|
|
@ -1,8 +0,0 @@
|
|||
import { expectResponseCode } from '../../utils/apiUtils'
|
||||
import { FrontendConfig } from './types'
|
||||
|
||||
export const getFrontendConfig = async (baseUrl: string): Promise<FrontendConfig> => {
|
||||
const response = await fetch(`${baseUrl}config.json`)
|
||||
expectResponseCode(response)
|
||||
return await response.json() as Promise<FrontendConfig>
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
export interface FrontendConfig {
|
||||
backendUrl: string
|
||||
}
|
|
@ -1,15 +1,15 @@
|
|||
import { HistoryEntry } from '../components/landing/pages/history/history'
|
||||
import { expectResponseCode, getBackendUrl } from '../utils/apiUtils'
|
||||
import { expectResponseCode, getApiUrl } from '../utils/apiUtils'
|
||||
import { defaultFetchConfig } from './default'
|
||||
|
||||
export const getHistory = async (): Promise<HistoryEntry[]> => {
|
||||
const response = await fetch(getBackendUrl() + '/history')
|
||||
const response = await fetch(getApiUrl() + '/history')
|
||||
expectResponseCode(response)
|
||||
return await response.json() as Promise<HistoryEntry[]>
|
||||
}
|
||||
|
||||
export const setHistory = async (entries: HistoryEntry[]): Promise<void> => {
|
||||
const response = await fetch(getBackendUrl() + '/history', {
|
||||
const response = await fetch(getApiUrl() + '/history', {
|
||||
...defaultFetchConfig,
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
|
@ -20,7 +20,7 @@ export const setHistory = async (entries: HistoryEntry[]): Promise<void> => {
|
|||
}
|
||||
|
||||
export const deleteHistory = async (): Promise<void> => {
|
||||
const response = await fetch(getBackendUrl() + '/history', {
|
||||
const response = await fetch(getApiUrl() + '/history', {
|
||||
...defaultFetchConfig,
|
||||
method: 'DELETE'
|
||||
})
|
||||
|
@ -28,7 +28,7 @@ export const deleteHistory = async (): Promise<void> => {
|
|||
}
|
||||
|
||||
export const updateHistoryEntry = async (noteId: string, entry: HistoryEntry): Promise<HistoryEntry> => {
|
||||
const response = await fetch(getBackendUrl() + '/history/' + noteId, {
|
||||
const response = await fetch(getApiUrl() + '/history/' + noteId, {
|
||||
...defaultFetchConfig,
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(entry)
|
||||
|
@ -38,7 +38,7 @@ export const updateHistoryEntry = async (noteId: string, entry: HistoryEntry): P
|
|||
}
|
||||
|
||||
export const deleteHistoryEntry = async (noteId: string): Promise<void> => {
|
||||
const response = await fetch(getBackendUrl() + '/history/' + noteId, {
|
||||
const response = await fetch(getApiUrl() + '/history/' + noteId, {
|
||||
...defaultFetchConfig,
|
||||
method: 'DELETE'
|
||||
})
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { ImageProxyResponse } from '../components/editor/markdown-renderer/replace-components/image/types'
|
||||
import { expectResponseCode, getBackendUrl } from '../utils/apiUtils'
|
||||
import { expectResponseCode, getApiUrl } from '../utils/apiUtils'
|
||||
import { defaultFetchConfig } from './default'
|
||||
|
||||
export const getProxiedUrl = async (imageUrl: string): Promise<ImageProxyResponse> => {
|
||||
const response = await fetch(getBackendUrl() + '/media/proxy', {
|
||||
const response = await fetch(getApiUrl() + '/media/proxy', {
|
||||
...defaultFetchConfig,
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { LoginProvider } from '../redux/user/types'
|
||||
import { expectResponseCode, getBackendUrl } from '../utils/apiUtils'
|
||||
import { expectResponseCode, getApiUrl } from '../utils/apiUtils'
|
||||
import { defaultFetchConfig } from './default'
|
||||
|
||||
export const getMe = async (): Promise<meResponse> => {
|
||||
|
@ -16,7 +16,7 @@ export interface meResponse {
|
|||
}
|
||||
|
||||
export const updateDisplayName = async (displayName: string): Promise<void> => {
|
||||
const response = await fetch(getBackendUrl() + '/me', {
|
||||
const response = await fetch(getApiUrl() + '/me', {
|
||||
...defaultFetchConfig,
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
|
@ -28,7 +28,7 @@ export const updateDisplayName = async (displayName: string): Promise<void> => {
|
|||
}
|
||||
|
||||
export const changePassword = async (oldPassword: string, newPassword: string): Promise<void> => {
|
||||
const response = await fetch(getBackendUrl() + '/me/password', {
|
||||
const response = await fetch(getApiUrl() + '/me/password', {
|
||||
...defaultFetchConfig,
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
|
@ -41,7 +41,7 @@ export const changePassword = async (oldPassword: string, newPassword: string):
|
|||
}
|
||||
|
||||
export const deleteUser = async (): Promise<void> => {
|
||||
const response = await fetch(getBackendUrl() + '/me', {
|
||||
const response = await fetch(getApiUrl() + '/me', {
|
||||
...defaultFetchConfig,
|
||||
method: 'DELETE'
|
||||
})
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { expectResponseCode, getBackendUrl } from '../utils/apiUtils'
|
||||
import { expectResponseCode, getApiUrl } from '../utils/apiUtils'
|
||||
import { defaultFetchConfig } from './default'
|
||||
|
||||
interface LastChange {
|
||||
|
@ -19,13 +19,13 @@ export interface Note {
|
|||
}
|
||||
|
||||
export const getNote = async (noteId: string): Promise<Note> => {
|
||||
const response = await fetch(getBackendUrl() + `/notes/${noteId}`)
|
||||
const response = await fetch(getApiUrl() + `/notes/${noteId}`)
|
||||
expectResponseCode(response)
|
||||
return await response.json() as Promise<Note>
|
||||
}
|
||||
|
||||
export const deleteNote = async (noteId: string): Promise<void> => {
|
||||
const response = await fetch(getBackendUrl() + `/notes/${noteId}`, {
|
||||
const response = await fetch(getApiUrl() + `/notes/${noteId}`, {
|
||||
...defaultFetchConfig,
|
||||
method: 'DELETE'
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue