-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72bc4cf
commit 474acb2
Showing
6 changed files
with
213 additions
and
0 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,23 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="style.css"> | ||
<title>SpaceX Explorer</title> | ||
</head> | ||
<body> | ||
<header> | ||
<h1>SpaceX Explorer</h1> | ||
</header> | ||
<main> | ||
<section> | ||
<button id="fetchLaunches">Latest Launches</button> | ||
<button id="fetchRockets">Rockets</button> | ||
<button id="fetchMissions">Missions</button> | ||
<div id="dataDisplay"></div> | ||
</section> | ||
</main> | ||
<script src="index.js"></script> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
document.getElementById('fetchLaunches').addEventListener('click', async () => { | ||
await fetchData('/launches'); | ||
}); | ||
|
||
document.getElementById('fetchRockets').addEventListener('click', async () => { | ||
await fetchData('/rockets'); | ||
}); | ||
|
||
document.getElementById('fetchMissions').addEventListener('click', async () => { | ||
await fetchData('/missions'); | ||
}); | ||
|
||
async function fetchData(endpoint) { | ||
try { | ||
const response = await fetch(endpoint); | ||
const data = await response.json(); | ||
displayData(data); | ||
} catch (error) { | ||
console.error('Error fetching data:', error); | ||
document.getElementById('dataDisplay').textContent = 'Failed to fetch data.'; | ||
} | ||
} | ||
|
||
function displayData(data) { | ||
const displayDiv = document.getElementById('dataDisplay'); | ||
displayDiv.innerHTML = ''; | ||
|
||
if (Array.isArray(data)) { | ||
data.forEach(item => { | ||
const itemDiv = document.createElement('div'); | ||
itemDiv.classList.add('item'); | ||
itemDiv.innerHTML = ` | ||
<h3>${item.name || item.mission_name || item.rocket_name}</h3> | ||
<p>${item.details || item.description || item.mission_id}</p> | ||
`; | ||
displayDiv.appendChild(itemDiv); | ||
}); | ||
} else { | ||
displayDiv.textContent = 'No data available.'; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "spacex-explorer", | ||
"version": "1.0.0", | ||
"description": "A simple app to explore SpaceX data using the SpaceX API", | ||
"main": "server.js", | ||
"scripts": { | ||
"start": "node server.js" | ||
}, | ||
"author": "Your Name", | ||
"license": "ISC", | ||
"dependencies": { | ||
"express": "^4.17.1", | ||
"node-fetch": "^2.6.1" | ||
} | ||
} | ||
|
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,44 @@ | ||
const express = require('express'); | ||
const fetch = require('node-fetch'); | ||
|
||
const app = express(); | ||
app.use(express.static('public')); | ||
|
||
const SPACEX_API_BASE_URL = 'https://api.spacexdata.com/v4'; | ||
|
||
app.get('/launches', async (req, res) => { | ||
try { | ||
const response = await fetch(`${SPACEX_API_BASE_URL}/launches/latest`); | ||
const data = await response.json(); | ||
res.json(data); | ||
} catch (error) { | ||
console.error('Error fetching launches:', error); | ||
res.status(500).json({ error: 'Failed to fetch launches' }); | ||
} | ||
}); | ||
|
||
app.get('/rockets', async (req, res) => { | ||
try { | ||
const response = await fetch(`${SPACEX_API_BASE_URL}/rockets`); | ||
const data = await response.json(); | ||
res.json(data); | ||
} catch (error) { | ||
console.error('Error fetching rockets:', error); | ||
res.status(500).json({ error: 'Failed to fetch rockets' }); | ||
} | ||
}); | ||
|
||
app.get('/missions', async (req, res) => { | ||
try { | ||
const response = await fetch(`${SPACEX_API_BASE_URL}/missions`); | ||
const data = await response.json(); | ||
res.json(data); | ||
} catch (error) { | ||
console.error('Error fetching missions:', error); | ||
res.status(500).json({ error: 'Failed to fetch missions' }); | ||
} | ||
}); | ||
|
||
app.listen(3000, () => { | ||
console.log('Server is running on port 3000'); | ||
}); |
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,70 @@ | ||
body { | ||
font-family: 'Arial', sans-serif; | ||
background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d); | ||
color: #fff; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
min-height: 100vh; | ||
margin: 0; | ||
} | ||
|
||
header { | ||
text-align: center; | ||
margin-bottom: 20px; | ||
} | ||
|
||
header h1 { | ||
font-size: 3em; | ||
color: #fff; | ||
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.6); | ||
} | ||
|
||
main { | ||
background: rgba(0, 0, 0, 0.6); | ||
padding: 20px; | ||
border-radius: 10px; | ||
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3); | ||
width: 80%; | ||
max-width: 800px; | ||
text-align: center; | ||
} | ||
|
||
button { | ||
padding: 10px 20px; | ||
margin: 10px; | ||
font-size: 1.2em; | ||
color: #fff; | ||
background-color: #333; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
transition: background-color 0.3s; | ||
} | ||
|
||
button:hover { | ||
background-color: #555; | ||
} | ||
|
||
#dataDisplay { | ||
margin-top: 20px; | ||
text-align: left; | ||
} | ||
|
||
.item { | ||
background: rgba(255, 255, 255, 0.1); | ||
padding: 15px; | ||
margin: 10px 0; | ||
border-radius: 5px; | ||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); | ||
} | ||
|
||
.item h3 { | ||
margin-top: 0; | ||
color: #fdbb2d; | ||
} | ||
|
||
.item p { | ||
margin: 5px 0 0; | ||
} |