@@ -32,22 +32,7 @@ api.get('/', (req, res) => {
3232 // If the geolocation is successful, format the name of the returned location,
3333 // then call the weather API with the coordinates and timezone.
3434
35- if ( "regionName" in coords && "city" in coords && "country" in coords ) {
36- renderValues . locationName = `${ coords . city } , ${ coords . regionName } , ${ coords . country } `
37- } else if ( "country" in coords ) {
38- if ( "city" in coords ) {
39- renderValues . locationName = `${ coords . city } , ${ coords . country } `
40- } else if ( "regionName" in coords ) {
41- renderValues . locationName = `${ coords . regionName } , ${ coords . country } `
42- } else {
43- renderValues . locationName = coords . country
44- }
45- } else if ( "city" in coords ) {
46- renderValues . locationName = coords . city
47- } else {
48- renderValues . locationName = coords . regionName
49- }
50-
35+ renderValues . locationName = coords . locationName
5136 return weather ( coords . lat , coords . lon , coords . timezone )
5237 } ) . catch ( ( ) => {
5338 // If the geolocation fails, default to Toronto, Ontario, Canada, then call
@@ -92,11 +77,9 @@ api.get('/geolocate', (req, res) => {
9277 // will send a request to `/geolocate` to get the estimated coordinates
9378 // of the client's IP address. This will then return the coordinates to the
9479 // client, which will use them to call the weather API as it normally would.
95- geolocateFromIP ( req . ip ) . then ( ( coords ) => {
96- res . json ( coords )
97- } ) . catch ( ( e ) => {
98- res . json ( { status : 'error' , code : 500 , message : e . message } )
99- } )
80+ geolocateFromIP ( req . ip )
81+ . then ( coords => res . json ( coords ) )
82+ . catch ( e => res . json ( { status : 'error' , code : 500 , message : e . message } ) )
10083} )
10184
10285api . get ( '/weather' , ( req , res ) => {
0 commit comments