-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server.js now serves local API server with GET and POST endpoints. app.js now performs intended front-end functionality, including getting weather data , storing user input on the local server and updating the UI made small changes in index.html and style.css to fit front-end to purpose (also added additional user input form)
- Loading branch information
Showing
8 changed files
with
148 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
exports.port = process.env.PORT || 5001; | ||
exports.origin = process.env.ORIGIN || `http://localhost:${exports.port}` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,54 @@ | ||
/* Global Variables */ | ||
const baseURL = 'http://api.openweathermap.org/data/2.5/weather'; | ||
const key = '&APPID='; | ||
const keyValue = 'b6c2e555f36966be6615e36144ea6610'; | ||
const localURL = 'http://localhost'; | ||
const port = 5001; | ||
|
||
// Create a new date instance dynamically with JS | ||
let d = new Date(); | ||
let newDate = d.getMonth()+'.'+ d.getDate()+'.'+ d.getFullYear(); | ||
let month = d.getMonth() + 1; | ||
let newDate = d.getDate() + '/' + month + '/' + d.getFullYear(); | ||
|
||
|
||
/* Functions */ | ||
|
||
// GET call to obtain weather data with user-provided zip code and country code | ||
const getWeather = async (zip, country) => { | ||
const url = baseURL + '?zip=' + zip + ',' + country + key + keyValue; | ||
return await fetch(url).then(response => response.json()).then(response => response.main.temp); | ||
} | ||
|
||
// POST call to send user data from forms to own API server | ||
const postUserData = async (temperature, date, userResponse) => { | ||
fetch(localURL + ':' + port + '/post', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({temperature, date, userResponse}) | ||
}) | ||
} | ||
|
||
// GET call to obtain current project data object | ||
const getCurrentData = async () => { | ||
return await fetch(localURL + ':' + port + '/get').then(response => response.json()) | ||
} | ||
|
||
|
||
/* Execution */ | ||
|
||
// Adding click EventListener to "Generate" button in HTML | ||
|
||
document.getElementById('generate').addEventListener('click', async () => { | ||
const country = document.getElementById('country').value; | ||
const zip = document.getElementById('zip').value; | ||
const userResponse = document.getElementById('feelings').value; | ||
const temperature = await getWeather(zip, country); | ||
await postUserData(temperature, newDate, userResponse); | ||
await getCurrentData() | ||
.then((response) => { | ||
document.getElementById('date').innerText = response.date, | ||
document.getElementById('temp').innerText = response.temperature, | ||
document.getElementById('content').innerText = response.userResponse | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,52 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Weather Journal</title> | ||
<link href="https://fonts.googleapis.com/css?family=Oswald:400,600,700|Ranga:400,700&display=swap" rel="stylesheet"> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<div id = "app"> | ||
<div class ="holder headline"> | ||
Weather Journal App | ||
</div> | ||
<div class ="holder zip"> | ||
<label for="zip">Enter Zipcode here</label> | ||
<input type="text" id="zip" placeholder="enter zip code here"> | ||
</div> | ||
<div class ="holder feel"> | ||
<label for="feelings">How are you feeling today?</label> | ||
<textarea class= "myInput" id="feelings" placeholder="Enter your feelings here" rows="9" cols="50"></textarea> | ||
<button id="generate" type = "submit"> Generate </button> | ||
</div> | ||
<div class ="holder entry"> | ||
<div class = "title">Most Recent Entry</div> | ||
<div id = "entryHolder"> | ||
<div id = "date"></div> | ||
<div id = "temp"></div> | ||
<div id = "content"></div> | ||
</div> | ||
</div> | ||
</div> | ||
<script src="app.js" type="text/javascript"></script> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Weather Journal</title> | ||
<link href="https://fonts.googleapis.com/css?family=Oswald:400,600,700|Ranga:400,700&display=swap" rel="stylesheet"> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
|
||
<body> | ||
<div id = "app"> | ||
|
||
<div class ="holder headline"> | ||
Weather Journal App | ||
</div> | ||
|
||
<section class='holders2'> | ||
<div class ="holder-country"> | ||
<label for="country">Enter country code here</label> | ||
<input type="text" id="country" placeholder="enter country code here"> | ||
</div> | ||
|
||
<div class ="holder zip"> | ||
<label for="zip">Enter Zipcode here</label> | ||
<input type="text" id="zip" placeholder="enter zip code here"> | ||
</div> | ||
</section> | ||
|
||
<div class ="holder feel"> | ||
<label for="feelings">How are you feeling today?</label> | ||
<textarea class= "myInput" id="feelings" placeholder="Enter your feelings here" rows="3" cols="50"></textarea> | ||
<button id="generate" type = "submit"> Generate </button> | ||
</div> | ||
|
||
<div class ="holder entry"> | ||
|
||
<div class = "title">Most Recent Entry</div> | ||
|
||
<div id = "entryHolder"> | ||
<div id = "date"></div> | ||
<div id = "temp"></div> | ||
<div id = "content"></div> | ||
|
||
</div> | ||
|
||
</div> | ||
|
||
</div> | ||
<script src="app.js" type="text/javascript"></script> | ||
|
||
</body> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters