feat: use own proxy implementation instead of @nuxtjs/proxy

This commit is contained in:
Settel 2022-08-05 13:17:09 +02:00
parent 2465e87a86
commit 29e1d4fc1a
4 changed files with 18 additions and 38 deletions

View File

@ -4,12 +4,10 @@ const packageJson = fs.readFileSync('./package.json', 'utf-8')
const version = JSON.parse(packageJson).version || 0
export default defineNuxtConfig({
ssr: false,
srcDir: 'src/',
target: 'static',
modules: [
'@nuxtjs/proxy',
],
ssr: false,
telemetry: false,
buildModules: [
'@pinia/nuxt'
],
@ -17,7 +15,4 @@ export default defineNuxtConfig({
serverBaseUrl: '/',
version,
},
proxy: {
'/api/': 'http://localhost:32039',
}
})

View File

@ -9,7 +9,6 @@
"preview": "nuxt preview"
},
"devDependencies": {
"@nuxtjs/proxy": "^2.1.0",
"nuxt": "3.0.0-rc.6",
"sass": "^1.54.0",
"sass-loader": "^13.0.2"

View File

@ -0,0 +1,16 @@
// based on rudimadima's code from
// https://github.com/nuxt/framework/discussions/1223#discussioncomment-3113017
import httpProxy from 'http-proxy';
export default defineEventHandler((event) => {
const proxy = httpProxy.createProxyServer({
target: 'http://localhost:32039/',
});
return new Promise((resolve, reject) => {
proxy.web(event.req, event.res, {});
proxy.on('response', () => resolve(null))
proxy.on('error', e => reject(e))
});
});

View File

@ -508,13 +508,6 @@
vite-node "^0.18.1"
vite-plugin-checker "^0.4.9"
"@nuxtjs/proxy@^2.1.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@nuxtjs/proxy/-/proxy-2.1.0.tgz#fa7715a11d237fa1273503c4e9e137dd1bf5575b"
integrity sha512-/qtoeqXgZ4Mg6LRg/gDUZQrFpOlOdHrol/vQYMnKu3aN3bP90UfOUB3QSDghUUK7OISAJ0xp8Ld78aHyCTcKCQ==
dependencies:
http-proxy-middleware "^1.0.6"
"@pinia/nuxt@^0.3.1":
version "0.3.1"
resolved "https://registry.yarnpkg.com/@pinia/nuxt/-/nuxt-0.3.1.tgz#30d9a3fee43c4ff485694ecad4b44fdfe064079e"
@ -616,13 +609,6 @@
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"
integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==
"@types/http-proxy@^1.17.5":
version "1.17.9"
resolved "https://registry.yarnpkg.com/@types/http-proxy/-/http-proxy-1.17.9.tgz#7f0e7931343761efde1e2bf48c40f02f3f75705a"
integrity sha512-QsbSjA/fSk7xB+UXlCT3wHBy5ai9wOcNDWwZAtud+jXhwOM3l+EYZh8Lng4+/6n8uar0J7xILzqftJdJ/Wdfkw==
dependencies:
"@types/node" "*"
"@types/jsdom@^16.2.14":
version "16.2.15"
resolved "https://registry.yarnpkg.com/@types/jsdom/-/jsdom-16.2.15.tgz#6c09990ec43b054e49636cba4d11d54367fc90d6"
@ -2121,17 +2107,6 @@ http-errors@2.0.0:
statuses "2.0.1"
toidentifier "1.0.1"
http-proxy-middleware@^1.0.6:
version "1.3.1"
resolved "https://registry.yarnpkg.com/http-proxy-middleware/-/http-proxy-middleware-1.3.1.tgz#43700d6d9eecb7419bf086a128d0f7205d9eb665"
integrity sha512-13eVVDYS4z79w7f1+NPllJtOQFx/FdUW4btIvVRMaRlUY9VGstAbo5MOhLEuUgZFRHn3x50ufn25zkj/boZnEg==
dependencies:
"@types/http-proxy" "^1.17.5"
http-proxy "^1.18.1"
is-glob "^4.0.1"
is-plain-obj "^3.0.0"
micromatch "^4.0.2"
http-proxy@^1.18.1:
version "1.18.1"
resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.18.1.tgz#401541f0534884bbf95260334e72f88ee3976549"
@ -2298,11 +2273,6 @@ is-number@^7.0.0:
resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b"
integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==
is-plain-obj@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-3.0.0.tgz#af6f2ea14ac5a646183a5bbdb5baabbc156ad9d7"
integrity sha512-gwsOE28k+23GP1B6vFl1oVh/WOzmawBrKwo5Ev6wMKzPkaXaCDIQKzLnvsA42DRlbVTWorkgTKIviAKCWkfUwA==
is-primitive@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/is-primitive/-/is-primitive-3.0.1.tgz#98c4db1abff185485a657fc2905052b940524d05"