Skip to content

Commit 1e55cd8

Browse files
committed
modify import
1 parent f0d221d commit 1e55cd8

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

bageldb-nuxt/src/module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ const module: NuxtModule<ModuleOptions> = defineNuxtModule<ModuleOptions>({
3838
// Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack`
3939
addPlugin({
4040
src: resolver.resolve('./runtime/plugin'),
41-
// mode: 'server',
41+
mode: 'server',
42+
})
43+
addPlugin({
44+
src: resolver.resolve('./runtime/plugin'),
45+
mode: 'client',
4246
})
4347

4448
// Add auto imports

bageldb-nuxt/src/runtime/bageldb-nuxt.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@ import type { BagelUser } from '@bageldb/bagel-db/src/interfaces';
55
// import type { AxiosResponse } from 'axios';
66
import { parse, serialize } from './cookies';
77
import type { AxiosResponse } from 'axios';
8-
// import axios from 'axios';
8+
import axios from 'axios';
99

1010
const AUTH_ENDPOINT = 'https://auth.bageldb.com/api/public';
1111

1212
// let axios: AxiosStatic;
1313
// import('axios').then((axiosModule) => {
1414
// axios = axiosModule.default;
1515
// });
16-
let axiosImportPath: string;
17-
if (process.client) {
18-
axiosImportPath = 'axios/dist/esm/axios'
19-
} else {
20-
axiosImportPath = 'axios'
21-
}
16+
// if (process.client) {
17+
// } else {
18+
// axios = require('axios').default;
19+
// }
2220

2321
class BagelNuxtUser extends BagelUsersRequest {
2422
constructor({ instance }: { instance: any }) {
@@ -151,15 +149,10 @@ export default class BagelNuxt extends BagelDB {
151149
super(apiToken)
152150
this.ctx = ctx;
153151

152+
// @ts-expect-error
153+
this.axiosInstance = axios.create();
154154

155-
156-
import(axiosImportPath).then((axiosModule) => {
157-
this.axiosInstance = axiosModule.default.create({
158-
maxContentLength: Infinity,
159-
maxBodyLength: Infinity,
160-
});
161-
162-
this.axiosInstance
155+
this.axiosInstance
163156
.interceptors
164157
.request
165158
.use(
@@ -194,7 +187,7 @@ export default class BagelNuxt extends BagelDB {
194187
const config = error.config;
195188
config.headers["Authorization"] = `Bearer ${new BagelNuxtUser({ instance: this })._getAccessToken()}`;
196189
return new Promise((resolve, reject) => {
197-
axiosModule.default.request(config)
190+
axios.request(config)
198191
.then((response: unknown) => {
199192
resolve(response);
200193
})
@@ -208,7 +201,6 @@ export default class BagelNuxt extends BagelDB {
208201
}
209202
return Promise.reject(error);
210203
});
211-
});
212204
}
213205
// @ts-expect-error
214206
users() {

0 commit comments

Comments
 (0)