Skip to content

Commit 602d789

Browse files
committed
Add proxy module and update API endpoints in nuxt.config.ts
1 parent 426ebb2 commit 602d789

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

nuxt.config.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export default defineNuxtConfig({
4444
},
4545
modules: [
4646
'@nuxt-alt/auth',
47+
'@nuxt-alt/proxy',
4748
'@nuxt-alt/http',
4849
'@pinia/nuxt',
4950
'nuxt-quasar-ui',
@@ -73,17 +74,17 @@ export default defineNuxtConfig({
7374
},
7475
endpoints: {
7576
login: {
76-
url: `${SESAME_APP_API_URL}/core/auth/local`,
77+
url: `/api/core/auth/local`,
7778
method: 'post',
7879
headers: { 'Content-Type': 'application/json' },
7980
},
8081
refresh: {
81-
url: `${SESAME_APP_API_URL}/core/auth/refresh`,
82+
url: `/api/core/auth/refresh`,
8283
method: 'post',
8384
headers: { 'Content-Type': 'application/json' },
8485
},
85-
logout: { url: `${SESAME_APP_API_URL}/core/auth/logout`, method: 'post' },
86-
user: { url: `${SESAME_APP_API_URL}/core/auth/session`, method: 'get' },
86+
logout: { url: `/api/core/auth/logout`, method: 'post' },
87+
user: { url: `/api/core/auth/session`, method: 'get' },
8788
},
8889
redirect: {
8990
logout: '/login',
@@ -99,10 +100,19 @@ export default defineNuxtConfig({
99100
},
100101
},
101102
},
103+
proxy: {
104+
proxies: {
105+
'/api': {
106+
rewrite: (path: string) => path.replace(/^\/api/, ''),
107+
target: SESAME_APP_API_URL,
108+
changeOrigin: true,
109+
}
110+
},
111+
},
102112
http: {
103113
debug: /true|on|yes|1/i.test(`${process.env.DEBUG}`),
104-
browserBaseURL: SESAME_APP_API_URL,
105-
baseURL: SESAME_APP_API_URL,
114+
browserBaseURL: '/api',
115+
baseURL: '/api',
106116
},
107117
dayjs: {
108118
locales: ['fr', 'en'],

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@jsonforms/vue-vanilla": "^3.2.1",
2020
"@nuxt-alt/auth": "^3.1.6",
2121
"@nuxt-alt/http": "^1.7.10",
22+
"@nuxt-alt/proxy": "^2.5.8",
2223
"@pinia/nuxt": "^0.5.1",
2324
"@quasar/extras": "^1.16.9",
2425
"@vueuse/router": "^10.7.2",

src/layouts/default.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ onMounted(async () => {
131131
daemonVersion.value = daemonVersionRes.value?.data
132132
})
133133
134-
const esUrl = new URL(config.baseUrl + "/core/backends/sse")
134+
const esUrl = new URL(window.location.origin + "/api/core/backends/sse")
135135
esUrl.searchParams.append("id", '' + auth.user?._id)
136136
esUrl.searchParams.append("key", '' + auth.user?.sseToken)
137137
var es = new ReconnectingEventSource(esUrl)

yarn.lock

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,17 @@
889889
defu "^6.1.3"
890890
ufo "^1.3.2"
891891

892+
"@nuxt-alt/proxy@^2.5.8":
893+
version "2.5.8"
894+
resolved "https://registry.yarnpkg.com/@nuxt-alt/proxy/-/proxy-2.5.8.tgz#8fe08f0e29528723c7c4b0c95c31be5e801f3c80"
895+
integrity sha512-5Rrh31rMKSi7Atr/bbYTuKJnmMQJ/UlQhQCiI4GIPZwO+oNnKvpH1s2XRWaMfLwKGn3LI7dBdBrhrBklCxcCKg==
896+
dependencies:
897+
"@nuxt/kit" "^3.9.3"
898+
"@refactorjs/http-proxy" latest
899+
"@refactorjs/serialize" latest
900+
defu "^6.1.3"
901+
picocolors "^1.0.0"
902+
892903
"@nuxt/devalue@^2.0.2":
893904
version "2.0.2"
894905
resolved "https://registry.yarnpkg.com/@nuxt/devalue/-/devalue-2.0.2.tgz#5749f04df13bda4c863338d8dabaf370f45ef7c7"
@@ -1209,6 +1220,13 @@
12091220
resolved "https://registry.yarnpkg.com/@quasar/extras/-/extras-1.16.11.tgz#84b1efb9097a6e58c3ebfdd5da83ac658056a35c"
12101221
integrity sha512-sbTBHOA+Hi7ah0P6qSm+xfRXqwJ94ct3NKA3Lkq3iNPYuHD7VXbSWtP2eA7Cu9Fd0WjVoPbngf6yFGg46U3IfQ==
12111222

1223+
"@refactorjs/http-proxy@latest":
1224+
version "0.2.14"
1225+
resolved "https://registry.yarnpkg.com/@refactorjs/http-proxy/-/http-proxy-0.2.14.tgz#2139316ed452dae281bd7002455220d2374b98bd"
1226+
integrity sha512-JI35e5QjEWns3KPRw5j6cCiPN60GtOLR2bgr4hPr0kIgQaxVCVIEsWnalC0Avvy02a5a8NSmpjFbpoDESD1PxQ==
1227+
dependencies:
1228+
requires-port "^1.0.0"
1229+
12121230
"@refactorjs/ofetch@latest":
12131231
version "1.1.1"
12141232
resolved "https://registry.yarnpkg.com/@refactorjs/ofetch/-/ofetch-1.1.1.tgz#7bb09976e9e6afc4de5b4e9636a7af941b6387ec"
@@ -6017,6 +6035,11 @@ require-from-string@^2.0.2:
60176035
resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.2.tgz#89a7fdd938261267318eafe14f9c32e598c36909"
60186036
integrity sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==
60196037

6038+
requires-port@^1.0.0:
6039+
version "1.0.0"
6040+
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
6041+
integrity sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==
6042+
60206043
requrl@^3.0.2:
60216044
version "3.0.2"
60226045
resolved "https://registry.yarnpkg.com/requrl/-/requrl-3.0.2.tgz#d376104193b02a2d874dde68454c2db2dfeb0fac"

0 commit comments

Comments
 (0)