![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
hops-development-proxy
Advanced tools
hops-development-proxy
Hops preset that adds an API-proxy for development.
Hops apps are often run on the same host as their backend/api endpoints. However, when working locally, backend apps often run on a different host as the frontend application. This can cause issues with cross origin requests during development that are of no concern in the production environment.
This package allows to proxy requests to your api server which runs on a different host/port.
Add hops-development-proxy
to your project.
$ yarn add hops-development-proxy@next
# OR npm install --save hops-development-proxy@next
hops-development-proxy
attaches a proxy when the application runs in development mode. It does not do anything when run in production mode.
Name | Type | Default | Required | Description |
---|---|---|---|---|
proxy | String | Object | undefined | no | Proxy target configuration |
Configures where to proxy API requests to.
Simplest way to set up the proxy is to configure the proxy target URL as string. In this case, the proxy target URL is used for every request that is not an HTML document (i.e. a requested page) or an asset (js file, css file etc.) served by the webpack dev server.
Example
.hopsrc.js
module.exports = {
proxy: 'https://example.org/',
};
browser GET /
-> Is handled by your Hops application, because browser requests an html file.
GET /assets/main.js
-> Will always be handled by webpack dev server, because it takes precedence.
fetch GET /api/data
-> Is proxied to https://example.org/, results in https://example.org/api/data
being requested.
If more flexibility is needed, proxy
can also be configured as an object, where the keys represent express route matchers to be proxied and the values configure the respective proxy. In the config, any http-proxy-middleware option can be used.
.hopsrc.js
module.exports = {
proxy: {
'/api': { target: 'https://example.org/' },
'/legacy-api': { target: 'https://example.org/old' },
},
};
When the object notation is used, every request that is not handled by the webpack dev server, will be proxied as long as the route matches. This is also true for html documents.
Sometimes additional request headers are needed, for example to add a fake user id for the backend api. Since any http-proxy-middleware option can be used, you can make use of the onProxyReq
callback to add additional headers.
.hopsrc.js
module.exports = {
proxy: {
'/api': {
target: 'https://httpbin.org/anything/',
onProxyReq(proxyReq) {
proxyReq.setHeader('x-USER-ID', '27');
},
},
},
};
FAQs
Proxy
The npm package hops-development-proxy receives a total of 124 weekly downloads. As such, hops-development-proxy popularity was classified as not popular.
We found that hops-development-proxy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.