-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Remove all
onEnter
preload on server side, using client side …
…fetch (#473) * Refactor server architecture * Separate store files * Fix move all component data reset to componentWillUnmount * Add user server provider * Refactor cluster detail, add VM based and Helm components * [wip] feat: VM based cluster support addNodes, resizeCluster, deleteNodes * Fix Helm type cluster detail * Fix cluster detail store
- Loading branch information
Showing
97 changed files
with
2,783 additions
and
2,470 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,40 @@ | ||
const url = require('url'); | ||
const { useStaticRendering } = require('mobx-react'); | ||
const { getServerConfig } = require('lib/utils'); | ||
const RootStore = require('stores/RootStore').default; | ||
|
||
useStaticRendering(true); | ||
|
||
const rootStore = new RootStore(); | ||
rootStore.registerStores(); | ||
// initial state for client app store | ||
const store = {}; | ||
|
||
/** | ||
* Middleware for creating the store | ||
* @param ctx | ||
* @param next | ||
*/ | ||
module.exports = async (ctx, next) => { | ||
try { | ||
const config = getServerConfig(); | ||
|
||
// Create state for SSR | ||
ctx.store = rootStore; | ||
|
||
ctx.store.config = config; | ||
|
||
// attach api server to ctx | ||
let serverUrl = process.env.serverUrl || config.serverUrl; | ||
// local config for server | ||
const { config } = ctx.app; | ||
|
||
let apiVer = process.env.apiVersion || config.apiVersion || 'v1'; | ||
let serverUrl = process.env.serverUrl || config.serverUrl; | ||
|
||
// attach socket server | ||
let socketUrl = process.env.socketUrl || config.socketUrl; | ||
let apiVer = process.env.apiVersion || config.apiVersion || 'v1'; | ||
|
||
if (!serverUrl.startsWith('http')) { | ||
serverUrl = 'http://' + serverUrl; | ||
} | ||
let socketUrl = process.env.socketUrl || config.socketUrl; | ||
|
||
if (!socketUrl.startsWith('ws://')) { | ||
socketUrl = 'ws://' + socketUrl; | ||
} | ||
|
||
const clientId = process.env.clientId || config.clientId; | ||
const clientSecret = process.env.clientSecret || config.clientSecret; | ||
// url.resolve need first string starts with http | ||
ctx.store.apiServer = url.resolve(serverUrl, apiVer); | ||
ctx.store.socketUrl = socketUrl; | ||
ctx.store.clientId = clientId; | ||
ctx.store.clientSecret = clientSecret; | ||
if (!serverUrl.startsWith('http')) { | ||
serverUrl = 'http://' + serverUrl; | ||
} | ||
if (!socketUrl.startsWith('ws://')) { | ||
socketUrl = 'ws://' + socketUrl; | ||
} | ||
|
||
// attach login user info to store | ||
const user = decodeURIComponent(ctx.cookies.get('user') || '{}'); | ||
const role = decodeURIComponent(ctx.cookies.get('role') || ''); | ||
try{ | ||
ctx.store.user = JSON.parse(user); | ||
}catch(err){} | ||
// url.resolve need first string starts with http | ||
Object.assign(store, { | ||
config, | ||
socketUrl, | ||
apiServer: url.resolve(serverUrl, apiVer), | ||
clientId: process.env.clientId || config.clientId, | ||
clientSecret: process.env.clientSecret || config.clientSecret | ||
}); | ||
|
||
if (role === 'user') { | ||
ctx.store.user.isDev = false; | ||
ctx.store.user.isNormal = true; | ||
} | ||
ctx.store = store; | ||
|
||
await next(); | ||
} catch (err) { | ||
ctx.app.reportErr(err, ctx); | ||
} | ||
await next(); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.