diff --git a/index.mjs b/index.mjs index a8e0b10..40c3a7c 100644 --- a/index.mjs +++ b/index.mjs @@ -60,16 +60,34 @@ const index = (req, res) => { }); }; +const geoip = (req, res) => { + res.set({ + 'x-geoip-city': 'Orlando', + 'x-geoip-country': 'US', + 'x-geoip-country-name': 'United States', + 'x-geoip-country-region': 'FL', + 'x-geoip-country-region-name': 'Florida', + 'x-geoip-latitude': '28.52135', + 'x-geoip-longitude': '-81.41079', + 'x-geoip-postal-code': '32789', + 'x-geoip-time-zone': 'America/New_York', + 'content-type': 'application/json', + }); + res.json({}); +}; + // debugging if (process.env?.DIST === '1') { // distribution app.use('/images', express.static('./server/images')); app.use('/fonts', express.static('./server/fonts')); app.use('/scripts', express.static('./server/scripts')); + app.use('/geoip', geoip); app.use('/', express.static('./dist')); } else { // debugging app.get('/index.html', index); + app.use('/geoip', geoip); app.get('/', index); app.get('*name', express.static('./server')); } diff --git a/server/scripts/index.mjs b/server/scripts/index.mjs index 437efbf..d14b6e1 100644 --- a/server/scripts/index.mjs +++ b/server/scripts/index.mjs @@ -78,6 +78,7 @@ const init = () => { onSelect(suggestion) { autocompleteOnSelect(suggestion); }, width: 490, }); + window.autoComplete = autoComplete; // attempt to parse the url parameters const parsedParameters = parseQueryString(); @@ -371,6 +372,10 @@ const btnGetGpsClick = async () => { const position = await getPosition(); const { latitude, longitude } = position.coords; + getForecastFromLatLon(latitude, longitude, true); +}; + +const getForecastFromLatLon = (latitude, longitude, fromGps = false) => { const txtAddress = document.querySelector(TXT_ADDRESS_SELECTOR); txtAddress.value = `${round2(latitude, 4)}, ${round2(longitude, 4)}`; @@ -380,7 +385,7 @@ const btnGetGpsClick = async () => { const query = `${location.city}, ${location.state}`; localStorage.setItem('latLon', JSON.stringify({ lat: latitude, lon: longitude })); localStorage.setItem('latLonQuery', query); - localStorage.setItem('latLonFromGPS', true); + localStorage.setItem('latLonFromGPS', fromGps); txtAddress.value = `${location.city}, ${location.state}`; }); }; @@ -411,3 +416,6 @@ const getCustomCode = async () => { document.body.append(customElem); } }; + +// expose functions for external use +window.getForecastFromLatLon = getForecastFromLatLon; diff --git a/server/scripts/modules/autocomplete.mjs b/server/scripts/modules/autocomplete.mjs index 2da116a..83a701f 100644 --- a/server/scripts/modules/autocomplete.mjs +++ b/server/scripts/modules/autocomplete.mjs @@ -172,6 +172,11 @@ class AutoComplete { } } + setValue(newValue) { + this.currentValue = newValue; + this.elem.value = newValue; + } + onValueChange() { clearTimeout(this.onValueChange);