-
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.
Successfully reciveing the fetched data from Node.js on Next.js's ser…
…ver #12
- Loading branch information
Showing
2 changed files
with
23 additions
and
12 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 |
---|---|---|
@@ -1,17 +1,19 @@ | ||
import axios from 'axios' | ||
|
||
const backUrl = process.env.BACK_URL | ||
const backURL = process.env.NEXT_PUBLIC_BACK_URL | ||
|
||
async function fetchedData(path, params = null) { | ||
let url | ||
if (params !== null) { | ||
url = `${backUrl}/${path}/${params}` | ||
url = `${backURL}/${path}/${params}` | ||
} else { | ||
url = `${backUrl}/${path}` | ||
url = `${backURL}/${path}` | ||
} | ||
try { | ||
const { data: response } = await axios.get(`${url}`) | ||
return response | ||
} catch (err) { | ||
console.log(`Error is ${err}`, err) | ||
} | ||
|
||
const response = await axios(`${url}`) | ||
const data = await response.json() | ||
return data | ||
} | ||
export { backUrl, fetchedData } | ||
export { backURL, fetchedData } |