File tree Expand file tree Collapse file tree
counter/webapp/public/authorized Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,15 +13,15 @@ <h1><a href="#" id="logout">Logout</a></h1>
1313 fetch ( "/api/user" )
1414 . then ( response => response . text ( ) ,
1515 err => user . innerHTML = err . message )
16- . then ( text => user . innerHTML = text == '' ? 'anonymous' : text ) ;
16+ . then ( text => user . innerHTML = text === '' ? 'anonymous' : text ) ;
1717
1818 fetch ( "/api/count" )
1919 . then ( response => response . json ( ) ,
2020 err => count . innerHTML = err . message )
2121 . then ( cnt => count . innerHTML =
22- cnt == 1 ? 'first' :
23- cnt == 2 ? 'second' :
24- cnt == 3 ? 'third' :
22+ cnt === 1 ? 'first' :
23+ cnt === 2 ? 'second' :
24+ cnt === 3 ? 'third' :
2525 '' + cnt + '-th' ) ;
2626 } ;
2727
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ module welcome.examples.org {
1010
1111 @WebService (" /welcome" )
1212 service SimpleApi {
13+ @Inject Client client;
1314 @Inject db.WelcomeSchema schema;
1415
1516 @Get (" org" )
@@ -18,6 +19,13 @@ module welcome.examples.org {
1819 return org;
1920 }
2021
22+ @Get (" info" )
23+ @Produces (Text)
24+ String callerInfo (RequestIn request) {
25+ ResponseIn response = client.get ($" http://ip-api.com/json/{request.client}" );
26+ return response.body ?.bytes .unpackUtf8 () : " " ;
27+ }
28+
2129 @Get (" count" )
2230 Int count (RequestIn request) {
2331 using (val tx = schema.connection .createTransaction ()) {
Original file line number Diff line number Diff line change @@ -5,13 +5,23 @@ class App extends Component {
55
66 constructor ( ) {
77 super ( ) ;
8- this . state = { seconds : 0 , name : "" , count : "" } ;
8+ this . state = { seconds : 0 , name : "" , city : "" , count : "" } ;
99 this . handleClick = this . handleClick . bind ( this ) ;
1010
1111 fetch ( '/welcome/org' )
1212 . then ( response => response . json ( ) )
1313 . then ( name => this . setState ( state => ( { name : name } ) ) ) ;
1414
15+ fetch ( '/welcome/info' )
16+ . then ( response => response . json ( ) )
17+ . then ( info => {
18+ if ( info [ "status" ] === "fail" ) {
19+ this . setState ( state => ( { city : "your city" } ) ) ;
20+ } else {
21+ this . setState ( state => ( { city : info [ "city" ] } ) ) ;
22+ }
23+ } )
24+
1525 fetch ( '/welcome/count' )
1626 . then ( response => response . json ( ) )
1727 . then ( data =>
@@ -45,6 +55,8 @@ class App extends Component {
4555 < div >
4656 Welcome to { this . state . name } ! This is your { this . state . count } visit to our site!
4757 < p />
58+ How's the weather in { this . state . city } ?
59+ < p />
4860 < button onClick = { this . handleClick } > Reset timer</ button >
4961 < p />
5062 Timer:{ this . state . seconds }
You can’t perform that action at this time.
0 commit comments