import { createStore, applyMiddleware, compose } from 'redux'
import thunk from 'redux-thunk'
import promise from 'redux-promise'
import axios from 'axios'
import apiClient from './apiClient'
import apolloClient from './apolloClient'
import { intl as intlClient } from './intlReducer'
import createReducer, { sourceReqCreateReducer } from './createReducer'

const middlewares = [
  promise,
  thunk.withExtraArgument({
    intl: intlClient,
    api: apiClient,
    axios
  }),
  apolloClient().middleware()
]

export default (initialState, options) => {
  return createStore(
    createReducer({
      sourceRequest: sourceReqCreateReducer({
        host: (options && options.req && options.req.headers.host) || ''
      })
    }),
    initialState,
    compose(
      applyMiddleware(...middlewares)
    )
  )
}

@@ -553,174 +553,388 @@
 %7B%0A  
-return createStore(%0A    createReducer(%7B%0A      sourceRequest: sourceReqCreateReducer(%7B%0A        host: (options && options.req && options.req.headers.host) %7C%7C ''%0A      %7D
+const request = %7B%0A    host: '',%0A    protocol: 'http'%0A  %7D%0A%0A  if (options && options.req && options.req.headers) %7B%0A    const %7B headers %7D = options.req%0A    request.host = headers.host %7C%7C request.host%0A    request.protocol = (headers%5B'x-forwarded-proto'%5D && 'https') %7C%7C request.protocol%0A  %7D%0A%0A  return createStore(%0A    createReducer(%7B%0A      sourceRequest: sourceReqCreateReducer(request
 )%0A  

set source request protocol to redux state