Skip to content

Commit

Permalink
fix(https): add url schema to sys server config; support ssl depoy;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Sep 17, 2021
1 parent 69e5794 commit 296272a
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions deploy-scripts/.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SYS_SERVER_SECRET_SALT=system-server-abcdefg1234567

# exposed port of laf services
PUBLISH_PORT=80
APP_SERVICE_DEPLOY_URL_SCHEMA=http

# `*.local-dev.host` always resolved to 127.0.0.1, just for local development
# Replace it with your own domain which should be resolved(*.domain.com) to your server ip
Expand Down
1 change: 1 addition & 0 deletions deploy-scripts/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ services:
APP_SERVICE_IMAGE: ${APP_SERVICE_IMAGE:-lafyun/app-service:latest}
ACCOUNT_DEFAULT_APP_QUOTA: ${ACCOUNT_DEFAULT_APP_QUOTA:-2}
APP_SERVICE_DEPLOY_HOST: ${DEPLOY_DOMAIN:?err}:${PUBLISH_PORT:-8080}
APP_SERVICE_DEPLOY_URL_SCHEMA: ${APP_SERVICE_DEPLOY_URL_SCHEMA}
command: dockerize -wait tcp://mongo:27017 node dist/index.js
volumes:
- /var/run/docker.sock:/var/run/docker.sock
Expand Down
2 changes: 1 addition & 1 deletion deploy-scripts/update.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

docker pull lafyun/app-service:latest
docker-compose pull
docker-compose down
docker-compose up -d
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ services:
APP_SERVICE_IMAGE: lafyun/app-service:latest
ACCOUNT_DEFAULT_APP_QUOTA: 5
APP_SERVICE_DEPLOY_HOST: local-dev.host:8080 # `*.local-dev.host` always resolved to 127.0.0.1, used to local development
APP_SERVICE_DEPLOY_URL_SCHEMA: 'http'
command: npx nodemon
volumes:
- ./packages/system-server:/app
Expand Down
3 changes: 2 additions & 1 deletion packages/system-client/src/api/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ export async function importApplication(appid, import_data) {
export function getAppAccessUrl() {
const appid = store.state.app.appid
const domain = store.state.app.app_deploy_host
const url = `http://${appid}.${domain}`
const schema = store.state.app.app_deploy_url_schema || 'http'
const url = `${schema}://${appid}.${domain}`
return url
}
8 changes: 7 additions & 1 deletion packages/system-client/src/store/modules/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const state = {
*/
file_token: null,

app_deploy_host: null
app_deploy_host: null,
app_deploy_url_schema: 'http'
}

const mutations = {
Expand All @@ -51,6 +52,9 @@ const mutations = {
SET_APP_DEPLOY_HOST: (state, domain) => {
state.app_deploy_host = domain
},
SET_APP_DEPLOY_URL_SCHEMA: (state, schema) => {
state.app_deploy_url_schema = schema
},
CLEAR_STATE: (state) => {
state.application = null
state.appid = null
Expand All @@ -59,6 +63,7 @@ const mutations = {
state.debug_token = null
state.file_token = null
state.app_deploy_host = null
state.app_deploy_url_schema = 'http'
}
}

Expand All @@ -75,6 +80,7 @@ const actions = {
commit('SET_DEBUG_TOKEN', res.data?.debug_token)
commit('SET_FILE_TOKEN', res.data?.file_token)
commit('SET_APP_DEPLOY_HOST', res.data?.app_deploy_host)
commit('SET_APP_DEPLOY_URL_SCHEMA', res.data?.app_deploy_url_schema)
},
clearStates({ commit }) {
commit('CLEAR_STATE')
Expand Down
8 changes: 8 additions & 0 deletions packages/system-server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ export default class Config {
return process.env.APP_SERVICE_DEPLOY_HOST ?? ''
}

/**
* The schema of app deployed url: `http` | `https`.
* Default value is `http`.
*/
static get APP_SERVICE_DEPLOY_URL_SCHEMA(): string {
return process.env.APP_SERVICE_DEPLOY_URL_SCHEMA ?? 'http'
}

/**
* The max old space size of node vm of application service, default is 256mb
* @see --max_old_space_size of node argv
Expand Down
6 changes: 4 additions & 2 deletions packages/system-server/src/router/application/get.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author: Maslow<wangfugen@126.com>
* @Date: 2021-08-30 15:22:34
* @LastEditTime: 2021-09-10 17:10:54
* @LastEditTime: 2021-09-17 16:30:27
* @Description:
*/

Expand Down Expand Up @@ -75,6 +75,7 @@ export async function handleGetApplicationByAppid(req: Request, res: Response) {
}

const app_deploy_host = Config.APP_SERVICE_DEPLOY_HOST
const app_deploy_url_schema = Config.APP_SERVICE_DEPLOY_URL_SCHEMA

app.config = undefined
return res.send({
Expand All @@ -84,7 +85,8 @@ export async function handleGetApplicationByAppid(req: Request, res: Response) {
roles,
debug_token,
file_token,
app_deploy_host
app_deploy_host,
app_deploy_url_schema
}
})
}

0 comments on commit 296272a

Please sign in to comment.