-
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.
Merge pull request #89 from haard18/changed_unsplash
Changed unsplash folder into the existingAPI Folder
- Loading branch information
Showing
12 changed files
with
1,066 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
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 @@ | ||
UNSPLASH_ACCESS="YOUR_ACCESS" |
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 @@ | ||
node_modules | ||
.env |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,53 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Image Gallery</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<h1>Image Gallery</h1> | ||
|
||
<form id="searchForm"> | ||
<input type="text" id="keywordInput" placeholder="Enter keyword"> | ||
<button type="submit">Search</button> | ||
</form> | ||
|
||
<button id="randomImageButton"> | ||
Get Me a Random Image | ||
</button> | ||
|
||
<div id="imageContainer"></div> | ||
|
||
<script> | ||
document.getElementById('searchForm').addEventListener('submit', async function(event) { | ||
event.preventDefault(); | ||
const keyword = document.getElementById('keywordInput').value.trim(); | ||
if (keyword !== '') { | ||
const response = await fetch(`http://localhost:3000/images/keywordImage?query=${encodeURIComponent(keyword)}`); | ||
const images = await response.json(); | ||
displayImages(images); | ||
} | ||
}); | ||
|
||
document.getElementById('randomImageButton').addEventListener('click', async function() { | ||
const response = await fetch('http://localhost:3000/images/randomImage'); | ||
const images = await response.json(); | ||
displayImages(images); | ||
}); | ||
|
||
async function displayImages(images) { | ||
const imageContainer = document.getElementById('imageContainer'); | ||
imageContainer.innerHTML = ''; | ||
|
||
images.forEach(imageUrl => { | ||
const img = document.createElement('img'); | ||
img.src = imageUrl; | ||
img.alt = 'Image'; | ||
imageContainer.appendChild(img); | ||
}); | ||
} | ||
</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,11 @@ | ||
const express = require('express'); | ||
const axios = require('axios'); | ||
const cors = require('cors'); | ||
const imageRouter = require('./routes/image') | ||
const app = express(); | ||
app.use(cors()); | ||
app.use(express.json()); | ||
app.use('/images', imageRouter); | ||
app.listen(3000, () => { | ||
console.log('Server is running on port 3000'); | ||
}); |
Oops, something went wrong.