import { generateReducer } from "../redux/generate_reducer"; import { ChangeApiHost, ChangeApiPort, ConfigState } from "./interfaces"; import { API } from "../api"; import { Actions } from "../constants"; const initialState: ConfigState = { host: location.hostname, // It gets annoying to manually change the port # in dev mode. // I automatically point to port 3000 on local. port: API.inferPort() }; export const configReducer = generateReducer(initialState) .add(Actions.CHANGE_API_PORT, (s, { payload }) => { s.port = payload.port.replace(/\D/g, ""); return s; }) .add(Actions.CHANGE_API_HOST, (s, { payload }) => { s.host = payload.host; return s; });