File tree Expand file tree Collapse file tree 4 files changed +54
-13
lines changed Expand file tree Collapse file tree 4 files changed +54
-13
lines changed Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ with custom values to setup a completely independent project:
91
91
92
92
aws ssm put-parameter --type "String" \
93
93
--name "/app/aws-lambda-edge/experimental/appConfig" \
94
- --value '{"title":"Lambda@Edge Immutable Web App (Experimental)","reportUri":"https://httpbin.org/post"}'
94
+ --value '{"title":"Lambda@Edge Immutable Web App (Experimental)","reportUri":"https://httpbin.org/post","api":"https://httpbin.org" }'
95
95
```
96
96
5 . Build and deploy the initial version with
97
97
```
@@ -118,7 +118,7 @@ with custom values to setup a completely independent project:
118
118
119
119
aws ssm put-parameter --type "String" \
120
120
--name "/app/aws-lambda-edge/live/appConfig" \
121
- --value '{"title":"Lambda@Edge Immutable Web App","reportUri":"https://httpbin.org/post"}'
121
+ --value '{"title":"Lambda@Edge Immutable Web App","reportUri":"https://httpbin.org/post","api":"https://httpbin.org" }'
122
122
123
123
npm run build
124
124
npm run deploy:assets
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+
3
+ import Data from './data'
4
+
5
+ import './main.css'
6
+
7
+ const App = ( { title, api } ) => (
8
+ < main >
9
+ < h1 > { title } </ h1 >
10
+ < div className = 'logo' />
11
+ < Data api = { api } />
12
+ </ main >
13
+ )
14
+
15
+ export default App
Original file line number Diff line number Diff line change
1
+ /* global fetch */
2
+
3
+ import React , { Component } from 'react'
4
+
5
+ class Data extends Component {
6
+ constructor ( ...args ) {
7
+ super ( ...args )
8
+ this . state = { data : null }
9
+ }
10
+
11
+ componentWillMount ( ) {
12
+ loadData ( this . props . api )
13
+ . then ( data => { this . setState ( { data } ) } )
14
+ . catch ( console . error )
15
+ }
16
+
17
+ render ( ) {
18
+ if ( this . state . data === null ) return null
19
+ return < p > { this . state . data . uuid } </ p >
20
+ }
21
+ }
22
+
23
+ const loadData = api => fetch ( `${ api } /uuid` ) . then ( d => d . json ( ) )
24
+
25
+ export default Data
Original file line number Diff line number Diff line change 1
1
import React from 'react'
2
2
import { render } from 'react-dom'
3
3
4
- import './main.css'
4
+ import App from './app'
5
+
6
+ const rootElementId = 'root'
5
7
6
8
const defaultAppConfig = {
7
- title : 'Lambda@Edge Immutable Web App'
9
+ title : 'Lambda@Edge Immutable Web App' ,
10
+ api : 'https://httpbin.org'
8
11
}
9
12
10
- const { title } = window . config || defaultAppConfig
11
-
12
- const App = ( { title } ) => (
13
- < main >
14
- < h1 > { title } </ h1 >
15
- < div className = 'logo' />
16
- </ main >
17
- )
18
- const renderApp = ( ) => render ( < App title = { title } /> , document . getElementById ( 'root' ) )
13
+ const renderApp = ( ) => {
14
+ const config = window . config || defaultAppConfig
15
+ render (
16
+ < App { ...config } /> ,
17
+ document . getElementById ( rootElementId )
18
+ )
19
+ }
19
20
20
21
if ( 'addEventListener' in document ) {
21
22
document . addEventListener ( 'DOMContentLoaded' , renderApp )
You can’t perform that action at this time.
0 commit comments