-
-
Save ashikka/a705ac9a34e9577ed5b5c5ef001c8acd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import express from "express"; | |
| import { createApi } from "unsplash-js"; | |
| import nodeFetch from "node-fetch"; | |
| const router = express.Router(); | |
| router.post("/", async (req, res) => { | |
| try { | |
| const pictureName = req.body.pictureName; | |
| const unsplash = createApi({ | |
| accessKey: process.env.ACCESS_KEY, | |
| fetch: nodeFetch, | |
| }); | |
| unsplash.search | |
| .getPhotos({ query: pictureName, page: 1, perPage: 10 }) | |
| .then((result) => { | |
| if (result.errors) { | |
| res.json({ success: false, message: result.errors[0] }); | |
| } else { | |
| res.json({ success: true, message: result.response }); | |
| } | |
| }); | |
| } catch (e) { | |
| res.json({ success: false, message: e }); | |
| } | |
| }); | |
| export default router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment