Setup simple SSR, untested

This commit is contained in:
Jerko Steiner 2019-03-14 12:38:34 +05:00
parent 949b008208
commit 360dc83ded
6 changed files with 15 additions and 7 deletions

View File

@ -0,0 +1,3 @@
export function CsrfToken(state = '') {
return state
}

View File

@ -0,0 +1 @@
export * from './CsrfTokenReducer'

View File

@ -1,5 +1,6 @@
export * from './actions'
export * from './components'
export * from './csrf'
export * from './http'
export * from './login'
export * from './middleware'

View File

@ -2,17 +2,14 @@ import {PromiseMiddleware} from '../middleware'
import {
applyMiddleware,
createStore as create,
combineReducers,
Middleware,
Action,
// AnyAction,
DeepPartial,
ReducersMapObject,
// Reducer,
Reducer,
} from 'redux'
export interface ICreateStoreParams<State, A extends Action> {
reducers: ReducersMapObject<State, A | any>
reducer: Reducer<State, A>
state?: DeepPartial<State>
middleware?: Middleware[]
}
@ -25,7 +22,7 @@ export function createStore<State, A extends Action>(
) {
const middleware = params.middleware || [new PromiseMiddleware().handle]
return (state?: DeepPartial<State>) => create(
combineReducers(params.reducers),
params.reducer,
state,
applyMiddleware(...middleware),
)

View File

@ -47,7 +47,7 @@ export class TestUtils {
params: IRenderParams<State>,
) {
const store = this.createStore({
reducers: params.reducers,
reducer: this.combineReducers(params.reducers),
})(params.state)
const Component = params.connector.connect(params.select)

View File

@ -52,6 +52,7 @@ export class Application implements IApplication {
this.configureMiddleware(router)
this.configureRouter(router)
this.configureApiErrorHandling(router)
this.configureFrontend(router)
server.use(this.config.app.context, router)
this.configureGlobalErrorHandling(server)
@ -78,6 +79,7 @@ export class Application implements IApplication {
}
protected configureRouter(router: express.Router) {
// TODO use /api for LoginRoutes
router.use('/app', new routes.LoginRoutes(
this.userService,
this.authenticator,
@ -104,6 +106,10 @@ export class Application implements IApplication {
router.use('/api', new middleware.ErrorApiHandler(apiLogger).handle)
}
protected configureFrontend(router: express.Router) {
// Override this method
}
protected configureGlobalErrorHandling(server: express.Application) {
const apiLogger = this.getApiLogger()
server.use(new middleware.ErrorPageHandler(apiLogger).handle)