From 6df73c794ed931c05f0470044fd381d25b92c8a6 Mon Sep 17 00:00:00 2001 From: Sean Dokko Date: Tue, 25 Sep 2018 15:29:32 -0700 Subject: [PATCH] Implement baseUrl --- example/src/Demo.jsx | 1 + packages/api-explorer/dist/index.js | 10 ++++++++-- packages/api-explorer/src/Doc.jsx | 3 +++ packages/api-explorer/src/index.jsx | 3 +++ packages/api-logs/__tests__/index.test.jsx | 1 - packages/api-logs/index.jsx | 6 +++--- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/example/src/Demo.jsx b/example/src/Demo.jsx index 34f41c071..beac6f6ba 100644 --- a/example/src/Demo.jsx +++ b/example/src/Demo.jsx @@ -79,6 +79,7 @@ class Demo extends React.Component { oasFiles={{ 'api-setting': Object.assign(extensions.defaults, this.state.oas), }} + baseUrl={'/'} Logs={Logs} flags={{ correctnewlines: false, diff --git a/packages/api-explorer/dist/index.js b/packages/api-explorer/dist/index.js index 9d0db76dc..6be7d5973 100644 --- a/packages/api-explorer/dist/index.js +++ b/packages/api-explorer/dist/index.js @@ -31180,6 +31180,7 @@ function (_React$Component) { flags: _this2.props.flags, user: Cookie.getJSON('user_data'), Logs: _this2.props.Logs, + baseUrl: _this2.props.baseUrl, appearance: _this2.props.appearance, language: _this2.state.language, oauth: _this2.props.oauth, @@ -31204,6 +31205,7 @@ ApiExplorer.propTypes = { correctnewlines: PropTypes.bool }).isRequired, oauth: PropTypes.bool, + baseUrl: PropTypes.string.isRequired, Logs: PropTypes.func, suggestedEdits: PropTypes.bool.isRequired, tryItMetrics: PropTypes.func, @@ -31227,7 +31229,8 @@ ApiExplorer.defaultProps = { correctnewlines: false }, tryItMetrics: function tryItMetrics() {}, - Logs: undefined + Logs: undefined, + baseUrl: '/' }; module.exports = function (props) { @@ -37758,6 +37761,7 @@ function (_React$Component) { apiKey: this.props.apiKey, oas: this.oas, user: this.props.user, + baseUrl: this.props.baseUrl, operation: this.getOperation(), formData: this.state.formData, onChange: this.onChange, @@ -37878,6 +37882,7 @@ Doc.propTypes = { referenceLayout: PropTypes.string }).isRequired, language: PropTypes.string.isRequired, + baseUrl: PropTypes.string, oauth: PropTypes.bool.isRequired, suggestedEdits: PropTypes.bool.isRequired, apiKey: PropTypes.string, @@ -37893,7 +37898,8 @@ Doc.defaultProps = { }, apiKey: undefined, Logs: undefined, - user: undefined + user: undefined, + baseUrl: '/' }; /***/ }), diff --git a/packages/api-explorer/src/Doc.jsx b/packages/api-explorer/src/Doc.jsx index 8909311c0..4fab13368 100644 --- a/packages/api-explorer/src/Doc.jsx +++ b/packages/api-explorer/src/Doc.jsx @@ -250,6 +250,7 @@ class Doc extends React.Component { apiKey={this.props.apiKey} oas={this.oas} user={this.props.user} + baseUrl={this.props.baseUrl} operation={this.getOperation()} formData={this.state.formData} onChange={this.onChange} @@ -381,6 +382,7 @@ Doc.propTypes = { referenceLayout: PropTypes.string, }).isRequired, language: PropTypes.string.isRequired, + baseUrl: PropTypes.string, oauth: PropTypes.bool.isRequired, suggestedEdits: PropTypes.bool.isRequired, apiKey: PropTypes.string, @@ -398,4 +400,5 @@ Doc.defaultProps = { apiKey: undefined, Logs: undefined, user: undefined, + baseUrl: '/', }; diff --git a/packages/api-explorer/src/index.jsx b/packages/api-explorer/src/index.jsx index fd4280bc7..496983cc1 100644 --- a/packages/api-explorer/src/index.jsx +++ b/packages/api-explorer/src/index.jsx @@ -105,6 +105,7 @@ class ApiExplorer extends React.Component { flags={this.props.flags} user={Cookie.getJSON('user_data')} Logs={this.props.Logs} + baseUrl={this.props.baseUrl} appearance={this.props.appearance} language={this.state.language} oauth={this.props.oauth} @@ -133,6 +134,7 @@ ApiExplorer.propTypes = { correctnewlines: PropTypes.bool, }).isRequired, oauth: PropTypes.bool, + baseUrl: PropTypes.string.isRequired, Logs: PropTypes.func, suggestedEdits: PropTypes.bool.isRequired, tryItMetrics: PropTypes.func, @@ -156,6 +158,7 @@ ApiExplorer.defaultProps = { }, tryItMetrics: () => {}, Logs: undefined, + baseUrl: '/', }; module.exports = props => ( diff --git a/packages/api-logs/__tests__/index.test.jsx b/packages/api-logs/__tests__/index.test.jsx index d240741f3..35cdc7ceb 100644 --- a/packages/api-logs/__tests__/index.test.jsx +++ b/packages/api-logs/__tests__/index.test.jsx @@ -38,7 +38,6 @@ describe('Logs', () => { test('should be in a loading state', () => { const comp = shallow(); comp.setState({ loading: true }); - console.log('whoa dude: ', comp.html()); expect(comp.find('.loading-container').length).toBe(1); }); diff --git a/packages/api-logs/index.jsx b/packages/api-logs/index.jsx index cb1bfbd47..6abca2410 100644 --- a/packages/api-logs/index.jsx +++ b/packages/api-logs/index.jsx @@ -73,7 +73,7 @@ class Logs extends React.Component { } getData() { - const { oas, operation } = this.props; + const { oas, operation, baseUrl } = this.props; const { group } = this.state; this.setState({ loading: true }); @@ -91,8 +91,7 @@ class Logs extends React.Component { find.group = group; } - // TODO: make this url non-root so that it can work with parent - const reqUrl = `/api/logs?${querystring.stringify(find)}`; + const reqUrl = `${baseUrl}api/logs?${querystring.stringify(find)}`; return fetch(reqUrl).then(res => { return this.handleData(res); @@ -199,6 +198,7 @@ class Logs extends React.Component { Logs.propTypes = { oas: PropTypes.shape({}).isRequired, operation: PropTypes.shape({}).isRequired, + baseUrl: PropTypes.string.isRequired, user: PropTypes.shape({ keys: PropTypes.array, id: PropTypes.string,