-
-
Save sholladay/7316505d5f7cc5a9fc596973e1cb4c7d to your computer and use it in GitHub Desktop.
ky with proxy
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
import { ky } from './ky.config'; | |
const employeesUrl = 'employees'; | |
export async function fetchEmployees() { | |
return ky.get(employeesUrl).json(); | |
} |
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
import { fetchEmployees } from './api' | |
fetchEmployees().then(console.log).catch(e => console.error(e.message)) |
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
import ky from 'ky'; | |
const isProd = process.env.NODE_ENV === 'production'; | |
const prefixUrl = isProd ? '/api/v1/' : 'http://localhost:3000/api/v1/'; | |
const api = ky.create({ prefixUrl }); | |
export { api as ky }; |
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
const express = require('express'); | |
const proxy = require('http-proxy-middleware'); | |
const app = express(); | |
const target = 'http://dummy.restapiexample.com'; | |
app.use( | |
'/api/v1', | |
proxy({ | |
target, | |
changeOrigin: true, | |
secure: false, | |
logLevel: 'debug' | |
}) | |
); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment