1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-12-22 17:23:22 +01:00

move to kremalicious/location endpoint

This commit is contained in:
Matthias Kretschmann 2021-12-03 00:57:26 +00:00
parent ded48163d6
commit 2b9fe1cc92
Signed by: m
GPG Key ID: 606EEEF3C479A91F
6 changed files with 5 additions and 23 deletions

View File

@ -1,4 +1,2 @@
GATSBY_GITHUB_TOKEN=xxx GATSBY_GITHUB_TOKEN=xxx
GATSBY_TYPEKIT_ID=xxx GATSBY_TYPEKIT_ID=xxx
NOMADLIST_PROFILE=xxx
NOMADLIST_KEY=xxx

View File

@ -76,13 +76,13 @@ If you want to know how, have a look at the respective components:
On client-side, my current and, if known, my next physical location on a city level is fetched from my (private) [nomadlist.com](https://nomadlist.com) profile and displayed in the header. On client-side, my current and, if known, my next physical location on a city level is fetched from my (private) [nomadlist.com](https://nomadlist.com) profile and displayed in the header.
Fetching is split up into a serverless function, a hook, and display component. Fetching is done with a serverless function as to not expose the whole profile response into the browser. Requires `NOMADLIST_PROFILE` & `NOMADLIST_KEY` environment variables. Fetching is split up into a serverless function, a hook, and display component. Fetching is done with a serverless function as to not expose the whole profile response into the browser.
If you want to know how, have a look at the respective components: If you want to know how, have a look at the respective components:
- [`api/location.js`](api/location.js)
- [`src/hooks/useLocation.js`](src/hooks/useLocation.js) - [`src/hooks/useLocation.js`](src/hooks/useLocation.js)
- [`src/components/molecules/Location.jsx`](src/components/molecules/Location.jsx) - [`src/components/molecules/Location.jsx`](src/components/molecules/Location.jsx)
- [kremalicious/location](https://github.com/kremalicious/location)
### 💅 Theme switcher ### 💅 Theme switcher

View File

@ -1,15 +0,0 @@
import axios from 'axios'
export default async function getLocationHandler(req, res) {
if (!process.env.NOMADLIST_PROFILE) return
try {
const response = await axios(
`https://nomadlist.com/@${process.env.NOMADLIST_PROFILE}.json?key=${process.env.NOMADLIST_KEY}`
)
if (!response?.data) return
res.json(response.data.location)
} catch (error) {
res.status(500).send(error)
}
}

View File

@ -1 +0,0 @@
../api

View File

@ -37,7 +37,7 @@ export default function Location({ hide }) {
const isDifferentCountry = now?.country !== next?.country const isDifferentCountry = now?.country !== next?.country
const relativeTime = new RelativeTime({ locale: 'en' }) const relativeTime = new RelativeTime({ locale: 'en' })
return !hide && now ? ( return !hide && now?.city ? (
<motion.aside <motion.aside
variants={moveInTop} variants={moveInTop}
className={styleLocation} className={styleLocation}

View File

@ -7,7 +7,7 @@ export const useLocation = () => {
useEffect(() => { useEffect(() => {
async function fetchData() { async function fetchData() {
try { try {
const response = await axios(`/api/location`) const response = await axios('https://location.kremalicious.com')
if (!response) return if (!response) return
setLocation(response.data) setLocation(response.data)
} catch (error) { } catch (error) {