nuxt-alt / proxy Goto Github PK
View Code? Open in Web Editor NEWAn alternative module to @nuxtjs/proxy
License: MIT License
An alternative module to @nuxtjs/proxy
License: MIT License
In my proxy, this used to work with Node 18.18.2:
proxyReq.getHeaderNames().forEach((headerName) => {
proxyReq.removeHeader(headerName);
});
When using Node 20.10.0 (LTS), the call times out
proxyReq.removeHeader(headerName);
it works again ๐
I defined a plugin in which I used
globalThis.$fetch = ofetch.create({
// Options here (baseUrl, interceptors etc.
})
to configure $fetch globally. When doing this, any proxy request causes this error:
http proxy error:Error: socket hang up
at connResetException (node:internal/errors:720:14)
at TLSSocket.socketOnEnd (node:_http_client:525:23)
at TLSSocket.emit (node:events:529:35)
at endReadableNT (node:internal/streams/readable:1368:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
timestamp: true,
error: Error: socket hang up
at connResetException (node:internal/errors:720:14)
at TLSSocket.socketOnEnd (node:_http_client:525:23)
at TLSSocket.emit (node:events:529:35)
at endReadableNT (node:internal/streams/readable:1368:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: 'ECONNRESET'
}
}
Should globalThis.$fetch not be overridden when using this plugin? ๐ค
I believe I have configured the module correctly, but I am receiving an error from TS. See below.
Related to the proxy
key not being defined on type NuxtConfig
.
Is this an issue with my project configuration? Is there a step I am missing? Should I attempt to extend NuxtConfig
?
Argument of type '{ modules: string[]; proxy: { proxies: { '^//auth/.*': { target: string; changeOrigin: boolean; rewrite: (path: string) => string; }; }; }; }' is not assignable to parameter of type 'NuxtConfig'.
Object literal may only specify known properties, and 'proxy' does not exist in type 'NuxtConfig'.ts(2345)
Unsure if there is a way, for example, to proxy:
http://localhost:3000/api/some/path/here -> http://localhost:3005/some/path/here
In which "some path here" proxies every path
Since 2,4,0, the following error appears on windows when starting the app:
-> yarn build
-> node .output/server/index.mjs
PS C:\dev\nuxt-debug> node .output/server/index.mjs Listening on http://[::]:3000 [nitro] [unhandledRejection] Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:' at new NodeError (node:internal/errors:405:5) at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:136:11) at defaultLoad (node:internal/modules/esm/load:87:3) at nextLoad (node:internal/modules/esm/loader:163:28) at ESMLoader.load (node:internal/modules/esm/loader:603:26) at ESMLoader.moduleProvider (node:internal/modules/esm/loader:457:22) at new ModuleJob (node:internal/modules/esm/module_job:64:26) at #createModuleJob (node:internal/modules/esm/loader:480:17) at ESMLoader.getModuleJob (node:internal/modules/esm/loader:434:34) { code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME' }
It's the same problem as #17, only in Production mode ๐ค
This configuration does not work in Nuxt 3:
export default defineNuxtConfig({
modules: [
'@nuxt-alt/proxy'
],
proxy: {
/* module options */
}
});
Because the proxy
property is not part of the InputConfig<NuxtConfig, ConfigLayerMeta>
type.
How am I suppose to use this in Nuxt 3?
Hello and thanks for this awesome package!
I have a problem when ssr is enabled, the webpage takes forever to load and nothing happens.
In the console there is / -> http://localhost:3001/
I think this looks good tho.
I tested it with ssr: false
โ works, ssr: true
โ doesn't work. (same goes for ws)
"nuxt": "^3.9.1",
"@nuxt-alt/proxy": "^2.5.6"
proxy: {
debug: true,
experimental: {
listener: true
},
proxies: {
"/api": {
target: "http://localhost:3001/",
changeOrigin: true,
rewrite: (path: string) => path.replace(/^\/api/, '')
}
}
}
Running a GQL server on port 8080 on my local and proxying to it won't work when SSR is enabled in Nuxt 3
"@nuxt-alt/proxy": "^2.2.3", or "@nuxt-alt/proxy": "^2.4.8"
Nuxt 3.8.2 with Nitro 2.8.1
Can be sure, there are memory leak. When add this module, the memory up is huge.
When testing locally, my target (back-end) server is running with a self-signed cert.
Even when I start nuxt with NODE_TLS_REJECT_UNAUTHORIZED=0
the proxy fails to connect to the back-end server:
http proxy error:Error: self signed certificate in certificate chain 15:35:33
at TLSSocket.onConnectSecure (node:_tls_wrap:1535:34)
at TLSSocket.emit (node:events:513:28)
at TLSSocket._finishInit (node:_tls_wrap:949:8)
at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:730:12) {
timestamp: true,
error: Error: self signed certificate in certificate chain
at TLSSocket.onConnectSecure (node:_tls_wrap:1535:34)
at TLSSocket.emit (node:events:513:28)
at TLSSocket._finishInit (node:_tls_wrap:949:8)
at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:730:12) {
code: 'SELF_SIGNED_CERT_IN_CHAIN'
}
}
After upgrading to 2.4.2 from 2.3.2 proxy calls return 404 in the browser
log seems to indicate the calls are made though:
[dev] (Use `node --trace-warnings ...` to show where the warning was created)
[dev] :okapi: 200 - http://local.com:8099/okapiapi/v1/profile
[dev] /okapiapi/v1/profile -> https://local.com:8087/api []
[1] Error: ENOENT: no such file or directory, stat '/app/dist/public/index.html'
[dev] [nitro-runtime] request: 0.037ms
[dev] :okapi: 200 - http://local.com:8099/okapiapi/v1/config/ui
[dev] /okapiapi/v1/config/ui -> https://local.com:8087/api []
[1] Error: ENOENT: no such file or directory, stat '/app/dist/public/index.html'
[dev] [nitro-runtime] request: 0.027ms
[dev] :okapi: 200 - http://local.com:8099/api/session
[dev] [nitro-runtime] beforeResponse: 0.009ms
[dev] [nitro-runtime] afterResponse: 0.009ms
[dev] [nitro-runtime] request: 0.107ms
[dev] :okapi: 200 - http://local.com:8099/api/session
[dev] [nitro-runtime] beforeResponse: 0.005ms
[dev] [nitro-runtime] afterResponse: 0.008ms
Here's my config which works with 2.3.2: (I've tried several unsuccessful combinations with 2.4.2)
proxy: {
proxies: {
// with options
'/okapiapi': {
target: `https://local.com:${process.env.API_PORT}/api`,
changeOrigin: true,
// NOTE: does not work with rewirte to just /api
rewrite: (path: string) => path.replace(/^\/okapiapi/, ''),
secure: false,
},
},
experimental: {
// fetch: false,
importFunctions: false,
},
},
Nuxt version 3.8.1 (also tried nightly build)
After upgrading to 2.4.3, I am getting this error when starting my Nuxt App:
โ Nitro built in 3651 ms nitro 09:01:43
[nitro] [unhandledRejection] Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
at new NodeError (node:internal/errors:405:5)
at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:136:11)
at defaultLoad (node:internal/modules/esm/load:87:3)
at nextLoad (node:internal/modules/esm/loader:163:28)
at ESMLoader.load (node:internal/modules/esm/loader:603:26)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:457:22)
at new ModuleJob (node:internal/modules/esm/module_job:64:26)
at #createModuleJob (node:internal/modules/esm/loader:480:17)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:434:34) {
code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}
My nuxt config:
proxy: {
proxies: {
'/api': {
target: process.env.BACKEND_URL,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
xfwd: true,
configure: (proxy) => {
proxy.on('proxyReq', (proxyReq) => {
console.log('proxyReq', proxyReq);
});
},
},
},
},
Hello buddy,
First of all, thx for this great package.
Would it be possible to make the configure function execute during the build step?
//nuxt.config.ts
proxy: {
proxies: {
'/api/resources': {
target: process.env.API_URL,
rewrite: (path) => path.replace(/^\/api\/resources/, ''),
changeOrigin: true,
configure: (proxy, options) => {
options.headers = {
'authorization': 'Bearer ' + process.env.API_KEY,
'accept': 'application/json'
}
},
}
}
}
//.output/server/chunks/nitro/node-server.mjs
"configure": "(proxy, options) => {\n options.headers = {\n 'authorization': 'Bearer ' + process.env.API_KEY,\n 'accept': 'application/json' };\n\n }" } };
it writes process.env.API_KEY to the function instead of writing its actual value from the building process xD
As a workaround I am exporting this env variable to linux shell prior yarn start, but that would be great if it could just write the value itself so I wouldn't need to do it only for this variable.
Hi!
I have a nuxt3 project. I use the url as site.com/test-api/feed/300 and the following is written in the proxy settings:
'/test-api': { target: site2.com, changeOrigin: true, secure: false, rewrite: (path: string) => path.replace(/^\/test-api/, 'api') },
i get fault - TypeError [ERR_INVALID_URL]: Invalid URL
moreover, the proxy works correctly on the client. The problem is only from the server side. Thank you very much in advance for your help. This problem blocks further development. I will expect help
Hey, thanks for creating this package, it's working great besides one specific scenario but I might be doing something wrong.
I store an auth token with useCookie
and when refreshing the application, a middleware detects an existing token/cookie and will fetch the user from an API and populate the Pinia store so that the application state is restored.
This works great until deploying the app on Vercel which gives this error:
request to http://localhost:3000/proxy/api/v2/my/user, reason: connect ECONNREFUSED 127.0.0.1:3000
Looks like the proxy hasn't kicked in and rewritten the url at this point, but middleware run after plugins etc so would have thought it was be in place by the time this happens.
The proxy works perfectly during development and in production for both client/server requests, but this specific case is acting up. Do you have any ideas what cause be causing this or a better way to approach this?
Thanks!
using version 2.4.7
i got an error
http proxy error at /blogs:
Error: connect ECONNREFUSED ::1:1337
at __node_internal_captureLargerStackTrace (node:internal/errors:484:5)
at __node_internal_exceptionWithHostPort (node:internal/errors:662:12)
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1300:16)
nuxt.config.ts
export default defineNuxtConfig({
modules: ["@nuxt-alt/proxy"],
devtools: { enabled: true },
runtimeConfig: {
public: {
apiProxyUrl: process.env.API_PROXY_URL,
},
},
proxy: {
proxies: {
"/proxy": {
target: process.env.API_BASE_URL,
changeOrigin: true,
rewrite: path => path.replace("/proxy", ""),
headers: {
Authorization: `Bearer ${process.env.API_TOKEN}`,
},
},
},
},
});
tried downgrading to version 2.3.2
and it works fine
After migrated @nuxtjs-alt/proxy 2.1.0
to @nuxt-alt/proxy 2.2.0
While startup nuxt dev server, following error reported :
โ Nitro built in 16193 ms
ERROR [worker reload] [worker init] Only URLs with a scheme in: file, data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
at new NodeError (node:internal/errors:387:5)
at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:1017:11)
at defaultResolve (node:internal/modules/esm/resolve:1097:3)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:837:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
at link (node:internal/modules/esm/module_job:75:36)
The situation looks similar to unjs/nitro#718
Hi we reinstall Nuxt and the packages from a project and we find this issue.
ERROR Cannot restart nuxt: crypto is not defined
at /node_modules/@refactorjs/serialize/dist/index.mjs:1:18
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
The only package with this dependencie is nuxt-alt/proxy. Can someone help us?
I am trying to proxy socket-io client to the nestjs WS gateway .
Here is the config of the module
proxy: {
enableProxy: true,
// fetch: true,
proxies: {
// with options
'/api': {
target: 'http://localhost:3000',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
},
'/socket.io': {
target: 'ws://localhost:3010',
changeOrigin: true,
ws: true,
},
},
},
Nuxt server is working at http://localhost:3005.
const socket = io({ transports: ['websocket'] })
Connection from vue component.
Nest js gateway running under 3010 port and also has transports: ['websocket'].
@WebSocketGateway(3010, {
transports: ['websocket'],
})
But i could not connect to nestjs gateway and got this warning:
WebSocket connection to 'ws://localhost:3005/socket.io/?EIO=4&transport=websocket' failed: WebSocket is closed before the connection is established.
Nuxt server logs:
/socket.io/?EIO=4&transport=websocket -> ws://localhost:3010
If i switch transport from websocket to polling both server and client side, config works fine.
How to configure plugin properly in that case?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.