Loading packages/rct-auth-store/src/rct-auth.store.js +1 −1 Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ class RctAuthStore { const { token } = body console.log(body) commonStore.setToken(token) await swaggerClientStore.buildClientWithToken(token) await swaggerClientStore.buildClientWithToken({ token }) runInAction(() => { this.inProgress = false notificationStore.newMessage('You are logged in!') Loading packages/rct-swagger-client-store/src/rct-swagger-client.store.js +13 −7 Original line number Diff line number Diff line import { observable, action } from 'mobx' import Swagger from 'swagger-client'; function getUrlTree(apiUrl) { function getUrlTree({ apiUrl }) { const l = document.createElement('a'); l.href = apiUrl; return { Loading @@ -9,12 +9,12 @@ function getUrlTree(apiUrl) { host: `${l.hostname}:${l.port}`, }; } async function resolveSwagger(apiUrl) { async function resolveSwagger({ apiUrl, swaggerUrl }) { const { spec } = await Swagger.resolve({ url: `${apiUrl}/swagger` url: `${swaggerUrl}/swagger` }) // parse api url and override the host and scheme in the swagger client const { host, scheme } = getUrlTree(apiUrl) const { host, scheme } = getUrlTree({ apiUrl }) spec.host = host spec.schemes = [scheme] return spec Loading @@ -23,11 +23,17 @@ async function resolveSwagger(apiUrl) { class RctSwaggerClientStore { @observable client = undefined @action async buildClient(apiUrl) { const spec = await resolveSwagger(apiUrl || 'http://localhost:10010/v1') @action async buildClient({ apiUrl, swaggerUrl }) { if (!apiUrl) { apiUrl = 'http://localhost:10010/v1' } if (!swaggerUrl) { swaggerUrl = apiUrl } const spec = await resolveSwagger({ apiUrl, swaggerUrl }) this.client = await new Swagger({ spec }) } @action async buildClientWithToken(token) { @action async buildClientWithToken({ token }) { this.client = await new Swagger({ spec: this.client.spec, authorizations: { Loading stories/index.js +3 −1 Original line number Diff line number Diff line Loading @@ -102,7 +102,9 @@ const HomeComponent = () => ( @observer class App extends Component { async componentWillMount() { await this.props.swaggerClientStore.buildClient(process.env.STORYBOOK_API_URL || 'http://localhost:10010/v1') await this.props.swaggerClientStore.buildClient({ apiUrl: process.env.STORYBOOK_API_URL || 'http://localhost:10010/v1' }) console.log(this.props.swaggerClientStore.client) this.props.commonStore.setAppLoaded() } Loading Loading
packages/rct-auth-store/src/rct-auth.store.js +1 −1 Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ class RctAuthStore { const { token } = body console.log(body) commonStore.setToken(token) await swaggerClientStore.buildClientWithToken(token) await swaggerClientStore.buildClientWithToken({ token }) runInAction(() => { this.inProgress = false notificationStore.newMessage('You are logged in!') Loading
packages/rct-swagger-client-store/src/rct-swagger-client.store.js +13 −7 Original line number Diff line number Diff line import { observable, action } from 'mobx' import Swagger from 'swagger-client'; function getUrlTree(apiUrl) { function getUrlTree({ apiUrl }) { const l = document.createElement('a'); l.href = apiUrl; return { Loading @@ -9,12 +9,12 @@ function getUrlTree(apiUrl) { host: `${l.hostname}:${l.port}`, }; } async function resolveSwagger(apiUrl) { async function resolveSwagger({ apiUrl, swaggerUrl }) { const { spec } = await Swagger.resolve({ url: `${apiUrl}/swagger` url: `${swaggerUrl}/swagger` }) // parse api url and override the host and scheme in the swagger client const { host, scheme } = getUrlTree(apiUrl) const { host, scheme } = getUrlTree({ apiUrl }) spec.host = host spec.schemes = [scheme] return spec Loading @@ -23,11 +23,17 @@ async function resolveSwagger(apiUrl) { class RctSwaggerClientStore { @observable client = undefined @action async buildClient(apiUrl) { const spec = await resolveSwagger(apiUrl || 'http://localhost:10010/v1') @action async buildClient({ apiUrl, swaggerUrl }) { if (!apiUrl) { apiUrl = 'http://localhost:10010/v1' } if (!swaggerUrl) { swaggerUrl = apiUrl } const spec = await resolveSwagger({ apiUrl, swaggerUrl }) this.client = await new Swagger({ spec }) } @action async buildClientWithToken(token) { @action async buildClientWithToken({ token }) { this.client = await new Swagger({ spec: this.client.spec, authorizations: { Loading
stories/index.js +3 −1 Original line number Diff line number Diff line Loading @@ -102,7 +102,9 @@ const HomeComponent = () => ( @observer class App extends Component { async componentWillMount() { await this.props.swaggerClientStore.buildClient(process.env.STORYBOOK_API_URL || 'http://localhost:10010/v1') await this.props.swaggerClientStore.buildClient({ apiUrl: process.env.STORYBOOK_API_URL || 'http://localhost:10010/v1' }) console.log(this.props.swaggerClientStore.client) this.props.commonStore.setAppLoaded() } Loading