mirror of
https://github.com/nocobase/nocobase
synced 2024-11-14 22:05:38 +00:00
feat(client): allows to store client information into session storage (#5424)
Some checks are pending
Build docker image / build-and-push (push) Waiting to run
Build pro image / build-and-push (push) Waiting to run
E2E / Build (push) Waiting to run
E2E / Core and plugins (push) Blocked by required conditions
E2E / plugin-workflow (push) Blocked by required conditions
E2E / plugin-workflow-approval (push) Blocked by required conditions
E2E / plugin-data-source-main (push) Blocked by required conditions
E2E / Comment on PR (push) Blocked by required conditions
NocoBase backend test / sqlite-test (20, false) (push) Waiting to run
NocoBase backend test / sqlite-test (20, true) (push) Waiting to run
NocoBase backend test / postgres-test (public, 20, nocobase, false) (push) Waiting to run
NocoBase backend test / postgres-test (public, 20, nocobase, true) (push) Waiting to run
NocoBase backend test / postgres-test (public, 20, public, false) (push) Waiting to run
NocoBase backend test / postgres-test (public, 20, public, true) (push) Waiting to run
NocoBase backend test / postgres-test (user_schema, 20, nocobase, false) (push) Waiting to run
NocoBase backend test / postgres-test (user_schema, 20, nocobase, true) (push) Waiting to run
NocoBase backend test / postgres-test (user_schema, 20, public, false) (push) Waiting to run
NocoBase backend test / postgres-test (user_schema, 20, public, true) (push) Waiting to run
NocoBase backend test / mysql-test (20, false) (push) Waiting to run
NocoBase backend test / mysql-test (20, true) (push) Waiting to run
NocoBase backend test / mariadb-test (20, false) (push) Waiting to run
NocoBase backend test / mariadb-test (20, true) (push) Waiting to run
NocoBase frontEnd test / frontend-test (18) (push) Waiting to run
Test on Windows / build (push) Waiting to run
Some checks are pending
Build docker image / build-and-push (push) Waiting to run
Build pro image / build-and-push (push) Waiting to run
E2E / Build (push) Waiting to run
E2E / Core and plugins (push) Blocked by required conditions
E2E / plugin-workflow (push) Blocked by required conditions
E2E / plugin-workflow-approval (push) Blocked by required conditions
E2E / plugin-data-source-main (push) Blocked by required conditions
E2E / Comment on PR (push) Blocked by required conditions
NocoBase backend test / sqlite-test (20, false) (push) Waiting to run
NocoBase backend test / sqlite-test (20, true) (push) Waiting to run
NocoBase backend test / postgres-test (public, 20, nocobase, false) (push) Waiting to run
NocoBase backend test / postgres-test (public, 20, nocobase, true) (push) Waiting to run
NocoBase backend test / postgres-test (public, 20, public, false) (push) Waiting to run
NocoBase backend test / postgres-test (public, 20, public, true) (push) Waiting to run
NocoBase backend test / postgres-test (user_schema, 20, nocobase, false) (push) Waiting to run
NocoBase backend test / postgres-test (user_schema, 20, nocobase, true) (push) Waiting to run
NocoBase backend test / postgres-test (user_schema, 20, public, false) (push) Waiting to run
NocoBase backend test / postgres-test (user_schema, 20, public, true) (push) Waiting to run
NocoBase backend test / mysql-test (20, false) (push) Waiting to run
NocoBase backend test / mysql-test (20, true) (push) Waiting to run
NocoBase backend test / mariadb-test (20, false) (push) Waiting to run
NocoBase backend test / mariadb-test (20, true) (push) Waiting to run
NocoBase frontEnd test / frontend-test (18) (push) Waiting to run
Test on Windows / build (push) Waiting to run
* feat(client): allows to store client information into session storage * fix: test error --------- Co-authored-by: chenos <chenlinxh@gmail.com>
This commit is contained in:
parent
156d99c724
commit
5108c8fe7c
@ -18,19 +18,20 @@ export default defineConfig({
|
||||
devtool: process.env.NODE_ENV === 'development' ? 'source-map' : false,
|
||||
favicons: [`${appPublicPath}favicon/favicon.ico`],
|
||||
metas: [{ name: 'viewport', content: 'initial-scale=0.1' }],
|
||||
links: [
|
||||
{ rel: 'stylesheet', href: `${appPublicPath}global.css` },
|
||||
],
|
||||
links: [{ rel: 'stylesheet', href: `${appPublicPath}global.css` }],
|
||||
headScripts: [
|
||||
{
|
||||
src: `${appPublicPath}browser-checker.js`,
|
||||
},
|
||||
{
|
||||
content: isDevCmd ? '' : `
|
||||
content: isDevCmd
|
||||
? ''
|
||||
: `
|
||||
window['__webpack_public_path__'] = '{{env.APP_PUBLIC_PATH}}';
|
||||
window['__nocobase_public_path__'] = '{{env.APP_PUBLIC_PATH}}';
|
||||
window['__nocobase_api_base_url__'] = '{{env.API_BASE_URL}}';
|
||||
window['__nocobase_api_client_storage_prefix__'] = '{{env.API_CLIENT_STORAGE_PREFIX}}';
|
||||
window['__nocobase_api_client_storage_type__'] = '{{env.API_CLIENT_STORAGE_TYPE}}';
|
||||
window['__nocobase_ws_url__'] = '{{env.WS_URL}}';
|
||||
window['__nocobase_ws_path__'] = '{{env.WS_PATH}}';
|
||||
`,
|
||||
@ -66,7 +67,7 @@ export default defineConfig({
|
||||
target: ['chrome80', 'es2020'],
|
||||
},
|
||||
codeSplitting: {
|
||||
jsStrategy: 'depPerChunk'
|
||||
jsStrategy: 'depPerChunk',
|
||||
},
|
||||
chainWebpack(config, { env }) {
|
||||
if (env === 'production') {
|
||||
|
@ -13,6 +13,9 @@ import devDynamicImport from '../.plugins/index';
|
||||
|
||||
export const app = new Application({
|
||||
apiClient: {
|
||||
storageType:
|
||||
// @ts-ignore
|
||||
window['__nocobase_api_client_storage_type__'] || process.env.API_CLIENT_STORAGE_TYPE || 'localStorage',
|
||||
// @ts-ignore
|
||||
storagePrefix:
|
||||
// @ts-ignore
|
||||
|
@ -291,6 +291,7 @@ function buildIndexHtml(force = false) {
|
||||
const data = fs.readFileSync(tpl, 'utf-8');
|
||||
const replacedData = data
|
||||
.replace(/\{\{env.APP_PUBLIC_PATH\}\}/g, process.env.APP_PUBLIC_PATH)
|
||||
.replace(/\{\{env.API_CLIENT_STORAGE_TYPE\}\}/g, process.env.API_CLIENT_STORAGE_TYPE)
|
||||
.replace(/\{\{env.API_CLIENT_STORAGE_PREFIX\}\}/g, process.env.API_CLIENT_STORAGE_PREFIX)
|
||||
.replace(/\{\{env.API_BASE_URL\}\}/g, process.env.API_BASE_URL || process.env.API_BASE_PATH)
|
||||
.replace(/\{\{env.WS_URL\}\}/g, process.env.WEBSOCKET_URL || '')
|
||||
@ -327,6 +328,7 @@ exports.initEnv = function initEnv() {
|
||||
APP_PORT: 13000,
|
||||
API_BASE_PATH: '/api/',
|
||||
API_CLIENT_STORAGE_PREFIX: 'NOCOBASE_',
|
||||
API_CLIENT_STORAGE_TYPE: 'localStorage',
|
||||
DB_DIALECT: 'sqlite',
|
||||
DB_STORAGE: 'storage/db/nocobase.sqlite',
|
||||
// DB_TIMEZONE: '+00:00',
|
||||
|
@ -8,7 +8,7 @@ const path = require('path');
|
||||
console.log('VERSION: ', packageJson.version);
|
||||
|
||||
function getUmiConfig() {
|
||||
const { APP_PORT, API_BASE_URL, API_CLIENT_STORAGE_PREFIX, APP_PUBLIC_PATH } = process.env;
|
||||
const { APP_PORT, API_BASE_URL, API_CLIENT_STORAGE_TYPE, API_CLIENT_STORAGE_PREFIX, APP_PUBLIC_PATH } = process.env;
|
||||
const API_BASE_PATH = process.env.API_BASE_PATH || '/api/';
|
||||
const PROXY_TARGET_URL = process.env.PROXY_TARGET_URL || `http://127.0.0.1:${APP_PORT}`;
|
||||
const LOCAL_STORAGE_BASE_URL = 'storage/uploads/';
|
||||
@ -41,6 +41,7 @@ function getUmiConfig() {
|
||||
'process.env.WS_PATH': process.env.WS_PATH,
|
||||
'process.env.API_BASE_URL': API_BASE_URL || API_BASE_PATH,
|
||||
'process.env.API_CLIENT_STORAGE_PREFIX': API_CLIENT_STORAGE_PREFIX,
|
||||
'process.env.API_CLIENT_STORAGE_TYPE': API_CLIENT_STORAGE_TYPE,
|
||||
'process.env.APP_ENV': process.env.APP_ENV,
|
||||
'process.env.VERSION': packageJson.version,
|
||||
'process.env.WEBSOCKET_URL': process.env.WEBSOCKET_URL,
|
||||
|
@ -267,6 +267,7 @@ export class MemoryStorage extends Storage {
|
||||
|
||||
interface ExtendedOptions {
|
||||
authClass?: any;
|
||||
storageType?: 'localStorage' | 'sessionStorage' | 'memory';
|
||||
storageClass?: any;
|
||||
storagePrefix?: string;
|
||||
}
|
||||
@ -300,10 +301,10 @@ export class APIClient {
|
||||
if (typeof instance === 'function') {
|
||||
this.axios = instance;
|
||||
} else {
|
||||
const { authClass, storageClass, storagePrefix = 'NOCOBASE_', ...others } = instance || {};
|
||||
const { authClass, storageType, storageClass, storagePrefix = 'NOCOBASE_', ...others } = instance || {};
|
||||
this.storagePrefix = storagePrefix;
|
||||
this.axios = axios.create(others);
|
||||
this.initStorage(storageClass);
|
||||
this.initStorage(storageClass, storageType);
|
||||
if (authClass) {
|
||||
this.auth = new authClass(this);
|
||||
}
|
||||
@ -317,14 +318,20 @@ export class APIClient {
|
||||
this.interceptors();
|
||||
}
|
||||
|
||||
private initStorage(storage?: any) {
|
||||
private initStorage(storage?: any, storageType = 'localStorage') {
|
||||
if (storage) {
|
||||
this.storage = new storage(this);
|
||||
} else if (typeof localStorage !== 'undefined') {
|
||||
this.storage = localStorage;
|
||||
} else {
|
||||
this.storage = new MemoryStorage();
|
||||
return;
|
||||
}
|
||||
if (storageType === 'localStorage' && typeof localStorage !== 'undefined') {
|
||||
this.storage = localStorage;
|
||||
return;
|
||||
}
|
||||
if (storageType === 'sessionStorage' && typeof sessionStorage !== 'undefined') {
|
||||
this.storage = sessionStorage;
|
||||
return;
|
||||
}
|
||||
this.storage = new MemoryStorage();
|
||||
}
|
||||
|
||||
interceptors() {
|
||||
|
Loading…
Reference in New Issue
Block a user