Skip to content

Commit

Permalink
feat: 🚸 improve dev workflow [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
AruSeito committed Jul 25, 2023
1 parent fa94297 commit 6cc8851
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
__snapshots__/**
*.test.tsx.snap
ILLA_PROTO.*
*.md
*.mdx
4 changes: 2 additions & 2 deletions apps/builder/.env.self
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VITE_CLOUD_URL=CLOUD_PATH
VITE_INSTANCE_ID=SELF_HOST_CLOUD
ILLA_APP_VERSION=0.0.0
ILLA_APP_VERSION=0.0.0
ILLA_APP_ENV=production
4 changes: 3 additions & 1 deletion apps/builder/src/api/http/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { isCloudVersion } from "@/utils/typeHelper"
export const HTTP_REQUEST_PUBLIC_BASE_URL = isCloudVersion
? `//${import.meta.env.VITE_API_BASE_URL}`
: // if use self-host,must has protocol,like this:http://localhost:8080
`${location.origin}`
import.meta.env.VITE_API_BASE_URL
? `${location.protocol}//${import.meta.env.VITE_API_BASE_URL}`
: `${location.origin}`

export const BUILDER_REQUEST_PREFIX = "/builder/api/v1"
export const BUILDER_WS_REQUEST_PREFIX = "/builder-ws/api/v1"
Expand Down
7 changes: 4 additions & 3 deletions apps/builder/src/api/ws/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ export const fixedWsURL = (wsURL: string) => {
? location.protocol
: new URL(HTTP_REQUEST_PUBLIC_BASE_URL).protocol
const wsProtocol = protocol === "https:" ? "wss://" : "ws://"
const wsPREFIX = `${wsProtocol}${
isCloudVersion ? location.host : new URL(HTTP_REQUEST_PUBLIC_BASE_URL).host
}`

if (!isCloudVersion) {
const wsPREFIX = `${wsProtocol}${
new URL(HTTP_REQUEST_PUBLIC_BASE_URL).host
}`
wsURL = `${wsPREFIX}${wsURL}`
}
return wsURL
Expand Down
22 changes: 15 additions & 7 deletions apps/builder/src/router/loader/selfHostAuthLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,30 @@ export const getSelfHostUserInfoLoader: LoaderFunction = async () => {
return redirect("/login")
}

export const getSelfHostTeamsInfoLoader: LoaderFunction = async () => {
export const getSelfHostTeamsInfoLoader: LoaderFunction = async (args) => {
const { params } = args
const { teamIdentifier } = params
const currentTeamInfoInDisk = getCurrentTeamInfo(store.getState())
if (currentTeamInfoInDisk?.id) {
return null
}
try {
const response = await fetchMyTeamsInfo()
const teamsInfo = response.data ?? []
if (!teamIdentifier) {
return redirect("/login")
}
const response = await fetchMyTeamsInfo()
const teamsInfo = response.data ?? []
const currentTeamInfo = teamsInfo.find(
(item) => item.identifier === teamIdentifier,
)
if (currentTeamInfo) {
store.dispatch(
teamActions.updateTeamReducer({
currentId: teamsInfo?.[0]?.id,
currentId: currentTeamInfo.id,
items: teamsInfo,
}),
)

return null
} catch (e) {
return redirect("/500")
}
return redirect("/404")
}
7 changes: 2 additions & 5 deletions apps/builder/src/utils/team.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { getCurrentId } from "@/redux/team/teamSelector"
import { ILLARoute } from "@/router"
import store from "@/store"
import { isCloudVersion } from "@/utils/typeHelper"

const teamID = "ILAfx4p1C7d0"

export const getTeamID = () => {
return isCloudVersion ? getCurrentId(store.getState()) : teamID
return getCurrentId(store.getState())
}

// maybe not same as current team
export const getCurrentPageTeamIdentifier = () => {
return isCloudVersion ? ILLARoute.state.matches[0].params.teamIdentifier : "0"
return ILLARoute.state.matches[0].params.teamIdentifier
}
8 changes: 4 additions & 4 deletions apps/builder/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import pkg from "./package.json"
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
const env = loadEnv(mode, process.cwd(), "")
const useHttps = env.VITE_USE_HTTPS === "true"
const BASIC_PLUGIN = [
mdx(),
react({
Expand All @@ -31,12 +32,11 @@ export default defineConfig(({ command, mode }) => {
visualizer(),
]

const DEVELOPMENT_PLUGIN = [basicSsl()]
const plugin = BASIC_PLUGIN
const version = pkg.version

if (command === "serve") {
plugin.push(...DEVELOPMENT_PLUGIN)
if (command === "serve" && useHttps) {
plugin.push(basicSsl())
} else {
if (env.VITE_INSTANCE_ID === "CLOUD" && env.ILLA_SENTRY_AUTH_TOKEN) {
plugin.push(
Expand Down Expand Up @@ -125,7 +125,7 @@ export default defineConfig(({ command, mode }) => {
},
server: {
port: 3000,
https: true,
https: useHttps,
},
preview: {
port: 4173,
Expand Down

0 comments on commit 6cc8851

Please sign in to comment.