Created
October 1, 2019 09:56
-
-
Save popuguytheparrot/f7f8c6a7cd454be72f52ddab66bc8370 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(data => 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 ? '' : 'http://localhost:3000'; | |
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