Skip to content

Commit c2531dc

Browse files
committed
Use gatsby-config and GraphQL for passing apiRoot URL
1 parent 4ee3bac commit c2531dc

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

config.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

gatsby-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
siteMetadata: {
33
title: 'JavaScriptMN',
4+
apiRoot: 'https://next-meetup-proxy-dnfelnhlmh.now.sh'
45
},
56
plugins: [
67
'gatsby-plugin-react-helmet',

src/components/Meetup.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { Component } from 'react'
2+
import PropTypes from 'prop-types'
23
import format from 'date-fns/format'
34
import 'whatwg-fetch'
4-
import config from '../../config.json'
5+
import { graphql, StaticQuery } from 'gatsby'
56

6-
const NEXT_MEETUP_URI = config.apiRoot
77

88
const MeetupDescription = ({ name, time, venue }) => (
99
<div className="next-event">
@@ -37,7 +37,7 @@ class Meetup extends Component {
3737
error: false,
3838
})
3939
window
40-
.fetch(NEXT_MEETUP_URI)
40+
.fetch(this.props.apiRoot)
4141
.then(res => res.json())
4242
.then(({ name, time, venue }) =>
4343
this.setState({
@@ -88,4 +88,22 @@ class Meetup extends Component {
8888
}
8989
}
9090

91-
export default Meetup
91+
Meetup.propTypes = {
92+
apiRoot: PropTypes.string.isRequired,
93+
}
94+
95+
const WrappedMeetup = () => (
96+
<StaticQuery
97+
query={graphql`
98+
query SiteApiRootQuery {
99+
site {
100+
siteMetadata {
101+
apiRoot
102+
}
103+
}
104+
}
105+
`}
106+
render={data => <Meetup apiRoot={data.site.siteMetadata.apiRoot}/>} />
107+
)
108+
109+
export default WrappedMeetup

0 commit comments

Comments
 (0)