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 './actions'
export * from './components' export * from './components'
export * from './csrf'
export * from './http' export * from './http'
export * from './login' export * from './login'
export * from './middleware' export * from './middleware'

View File

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

View File

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

View File

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