Skip to content

Commit

Permalink
feat: Node.js 运行环境外部映射端口增加校验 (#2808)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengkunwang223 authored Nov 5, 2023
1 parent e43de97 commit 9d1757d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions backend/app/service/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (err error) {
if err = checkPortExist(create.Port); err != nil {
return err
}
for _, export := range create.ExposedPorts {
if err = checkPortExist(export.HostPort); err != nil {
return err
}
}
if containerName, ok := create.Params["CONTAINER_NAME"]; ok {
if err := checkContainerName(containerName.(string)); err != nil {
return err
Expand Down Expand Up @@ -342,6 +347,11 @@ func (r *RuntimeService) Update(req request.RuntimeUpdate) error {
}
runtime.Port = req.Port
}
for _, export := range req.ExposedPorts {
if err = checkPortExist(export.HostPort); err != nil {
return err
}
}
if containerName, ok := req.Params["CONTAINER_NAME"]; ok {
envs, err := gotenv.Unmarshal(runtime.Env)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/website/runtime/node/operate/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ const rules = ref<any>({
HOST_IP: [Rules.requiredSelect],
EXEC_SCRIPT: [Rules.requiredSelect],
CONTAINER_NAME: [Rules.requiredInput, Rules.containerName],
CUSTOM_SCRIPT: [Rules.requiredInput],
},
});
const scripts = ref<Runtime.NodeScripts[]>([]);
Expand Down Expand Up @@ -456,7 +455,8 @@ const getRuntime = async (id: number) => {
runtime.exposedPorts = data.exposedPorts || [];
editParams.value = data.appParams;
searchApp(data.appID);
if (data.params['CUSTOM_SCRIPT'] == '0') {
if (data.params['CUSTOM_SCRIPT'] == undefined || data.params['CUSTOM_SCRIPT'] == '0') {
data.params['CUSTOM_SCRIPT'] = '0';
getScripts();
}
open.value = true;
Expand Down

0 comments on commit 9d1757d

Please sign in to comment.