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:
Philip Molares 2020-07-29 22:58:01 +02:00 committed by GitHub
parent 287d2e2729
commit d0fc96b929
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 173 additions and 182 deletions

View file

@ -0,0 +1,10 @@
import { store } from '../../utils/store'
import { ApiUrlActionType, ApiUrlObject, SetApiUrlAction } from './types'
export const setApiUrl = (state: ApiUrlObject): void => {
const action: SetApiUrlAction = {
type: ApiUrlActionType.SET_API_URL,
state
}
store.dispatch(action)
}

View file

@ -0,0 +1,15 @@
import { Reducer } from 'redux'
import { ApiUrlActions, ApiUrlActionType, ApiUrlObject, SetApiUrlAction } from './types'
export const initialState: ApiUrlObject = {
apiUrl: ''
}
export const ApiUrlReducer: Reducer<ApiUrlObject, ApiUrlActions> = (state: ApiUrlObject = initialState, action: ApiUrlActions) => {
switch (action.type) {
case ApiUrlActionType.SET_API_URL:
return (action as SetApiUrlAction).state
default:
return state
}
}

View file

@ -0,0 +1,17 @@
import { Action } from 'redux'
export enum ApiUrlActionType {
SET_API_URL = 'api-url/set'
}
export interface ApiUrlActions extends Action<ApiUrlActionType> {
type: ApiUrlActionType;
}
export interface SetApiUrlAction extends ApiUrlActions {
state: ApiUrlObject;
}
export interface ApiUrlObject {
apiUrl: string
}

View file

@ -1,11 +0,0 @@
import { BackendConfig } from '../../api/backend-config/types'
import { store } from '../../utils/store'
import { BackendConfigActionType, SetBackendConfigAction } from './types'
export const setBackendConfig = (state: BackendConfig): void => {
const action: SetBackendConfigAction = {
type: BackendConfigActionType.SET_BACKEND_CONFIG,
state: state
}
store.dispatch(action)
}

View file

@ -1,14 +0,0 @@
import { Action } from 'redux'
import { BackendConfig } from '../../api/backend-config/types'
export enum BackendConfigActionType {
SET_BACKEND_CONFIG = 'backend-config/set'
}
export interface BackendConfigActions extends Action<BackendConfigActionType>{
type: BackendConfigActionType;
}
export interface SetBackendConfigAction extends BackendConfigActions {
state: BackendConfig;
}

View file

@ -0,0 +1,11 @@
import { Config } from '../../api/config/types'
import { store } from '../../utils/store'
import { ConfigActionType, SetConfigAction } from './types'
export const setConfig = (state: Config): void => {
const action: SetConfigAction = {
type: ConfigActionType.SET_CONFIG,
state: state
}
store.dispatch(action)
}

View file

@ -1,8 +1,8 @@
import { Reducer } from 'redux'
import { BackendConfig } from '../../api/backend-config/types'
import { BackendConfigActions, BackendConfigActionType, SetBackendConfigAction } from './types'
import { Config } from '../../api/config/types'
import { ConfigActions, ConfigActionType, SetConfigAction } from './types'
export const initialState: BackendConfig = {
export const initialState: Config = {
allowAnonymous: true,
authProviders: {
facebook: false,
@ -43,10 +43,10 @@ export const initialState: BackendConfig = {
}
}
export const BackendConfigReducer: Reducer<(BackendConfig), BackendConfigActions> = (state: (BackendConfig) = initialState, action: BackendConfigActions) => {
export const ConfigReducer: Reducer<Config, ConfigActions> = (state: Config = initialState, action: ConfigActions) => {
switch (action.type) {
case BackendConfigActionType.SET_BACKEND_CONFIG:
return (action as SetBackendConfigAction).state
case ConfigActionType.SET_CONFIG:
return (action as SetConfigAction).state
default:
return state
}

14
src/redux/config/types.ts Normal file
View file

@ -0,0 +1,14 @@
import { Action } from 'redux'
import { Config } from '../../api/config/types'
export enum ConfigActionType {
SET_CONFIG = 'config/set'
}
export interface ConfigActions extends Action<ConfigActionType> {
type: ConfigActionType;
}
export interface SetConfigAction extends ConfigActions {
state: Config;
}

View file

@ -1,14 +0,0 @@
import { FrontendConfig } from '../../api/frontend-config/types'
import { store } from '../../utils/store'
import { FrontendConfigActionType, SetFrontendConfigAction } from './types'
export const setFrontendConfig = (state: FrontendConfig): void => {
const action: SetFrontendConfigAction = {
type: FrontendConfigActionType.SET_FRONTEND_CONFIG,
state: {
...state,
backendUrl: state.backendUrl + '/api/v2'
}
}
store.dispatch(action)
}

View file

@ -1,16 +0,0 @@
import { Reducer } from 'redux'
import { FrontendConfig } from '../../api/frontend-config/types'
import { FrontendConfigActions, FrontendConfigActionType, SetFrontendConfigAction } from './types'
const initialState: FrontendConfig = {
backendUrl: ''
}
export const FrontendConfigReducer: Reducer<(FrontendConfig), FrontendConfigActions> = (state: (FrontendConfig) = initialState, action: FrontendConfigActions) => {
switch (action.type) {
case FrontendConfigActionType.SET_FRONTEND_CONFIG:
return (action as SetFrontendConfigAction).state
default:
return state
}
}

View file

@ -1,14 +0,0 @@
import { Action } from 'redux'
import { FrontendConfig } from '../../api/frontend-config/types'
export enum FrontendConfigActionType {
SET_FRONTEND_CONFIG = 'frontend-config/set'
}
export interface FrontendConfigActions extends Action<FrontendConfigActionType> {
type: FrontendConfigActionType;
}
export interface SetFrontendConfigAction extends FrontendConfigActions {
state: FrontendConfig;
}

View file

@ -1,27 +1,27 @@
import { combineReducers, Reducer } from 'redux'
import { BackendConfig } from '../api/backend-config/types'
import { FrontendConfig } from '../api/frontend-config/types'
import { BackendConfigReducer } from './backend-config/reducers'
import { Config } from '../api/config/types'
import { ApiUrlReducer } from './api-url/reducers'
import { ApiUrlObject } from './api-url/types'
import { BannerReducer } from './banner/reducers'
import { BannerState } from './banner/types'
import { ConfigReducer } from './config/reducers'
import { EditorConfigReducer } from './editor/reducers'
import { EditorConfig } from './editor/types'
import { FrontendConfigReducer } from './frontend-config/reducers'
import { UserReducer } from './user/reducers'
import { MaybeUserState } from './user/types'
export interface ApplicationState {
user: MaybeUserState;
backendConfig: BackendConfig;
banner: BannerState;
frontendConfig: FrontendConfig;
editorConfig: EditorConfig;
user: MaybeUserState;
config: Config;
banner: BannerState;
apiUrl: ApiUrlObject;
editorConfig: EditorConfig;
}
export const allReducers: Reducer<ApplicationState> = combineReducers<ApplicationState>({
user: UserReducer,
backendConfig: BackendConfigReducer,
config: ConfigReducer,
banner: BannerReducer,
frontendConfig: FrontendConfigReducer,
apiUrl: ApiUrlReducer,
editorConfig: EditorConfigReducer
})