0.0.1-SNAPSHOT
wangbing 5 years ago
parent 1719a94030
commit 597b13390b

@ -148,6 +148,9 @@ public class AjaxController {
baseResponse.addError(ErrorType.BUSINESS_ERROR, "程序尚未运行");
return baseResponse;
}
// 刷新配置文件
flushConfig();
// 重新加载配置文件
ProcessUtil.execBat(nginxCtrl.getReloadCmd());
return baseResponse;
}
@ -210,10 +213,15 @@ public class AjaxController {
}
private void flushConfig() {
Writer wr = null;
try {
File config = nginxCtrl.getConfig();
HashMap<String, Object> context = new HashMap<>();
PortLoadResponse portLoadResponse = (PortLoadResponse) loadPort("", LocalData.getSysToken());
context.put("services",portLoadResponse.getResult());
Template template = freeMarkerConfigurer.getConfiguration().getTemplate("nginx.conf");
Writer wr = new OutputStreamWriter(new FileOutputStream(outfile), "UTF-8");
wr = new OutputStreamWriter(new FileOutputStream(config), "UTF-8");
//写入
template.process(context, wr);
//关闭流
@ -222,6 +230,12 @@ public class AjaxController {
e.printStackTrace();
} catch (TemplateException e) {
e.printStackTrace();
} finally {
try {
wr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

@ -71,7 +71,7 @@ public class NginxConfig {
nginxCtrl.setStopCmd(stop.getAbsolutePath());
nginxCtrl.setReloadCmd(reload.getAbsolutePath());
nginxCtrl.setVersionCmd(nginxHome.getAbsolutePath() + " -v ");
nginxCtrl.setConfig(new File(new File(nginxHome, "conf"), "nginx.conf"));
return nginxCtrl;
}
}

@ -25,24 +25,15 @@ public class Mapping {
*/
@TableField
private Long serviceId;
/**
* NAME -
*/
@TableField
private String name;
/**
* VALUE -
*/
@TableField
private String value;
/**
* BZ -
*/
private String context;
@TableField
private String location;
@TableField
private String bz;
@TableField
// @JsonFormat(timezone = "GMT+8", pattern = "yyyyMMddHHmmss")
private Date createTime;
@TableField
private boolean isDeleted;
@ -63,12 +54,20 @@ public class Mapping {
this.name = name;
}
public String getValue() {
return value;
public String getContext() {
return context;
}
public void setContext(String context) {
this.context = context;
}
public String getLocation() {
return location;
}
public void setValue(String value) {
this.value = value;
public void setLocation(String location) {
this.location = location;
}
public String getBz() {

@ -3,12 +3,15 @@ package com.example.module.admin.ent;
import com.example.frame.utils.ProcessUtil;
import java.io.File;
public class NginxCtrl {
private String startCmd = "start nginx";
private String stopCmd = "nginx.exe -s quit";
private String reloadCmd = "nginx.exe -s reload";
private String versionCmd = "nginx -v";
private File config = null;
public void doStart() {
ProcessUtil.exec(startCmd);
@ -54,6 +57,14 @@ public class NginxCtrl {
this.versionCmd = versionCmd;
}
public File getConfig() {
return config;
}
public void setConfig(File config) {
this.config = config;
}
public boolean isRunning() {
return ProcessUtil.findProcess("nginx.exe");
}

@ -7,6 +7,7 @@ import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
import org.hibernate.validator.constraints.Length;
import xyz.wbsite.wsqlite.anonation.TableField;
/**
* MappingCreateRequest -
@ -32,7 +33,10 @@ public class MappingCreateRequest extends BaseRequest {
@NotNull(message = "映射值不能为空")
@Pattern(regexp = "[^/]*", message = "映射值不能存在/")
@Pattern(regexp = "\\w*", message = "映射值需为英文")
private String value;
private String context;
@TableField
private String location;
/**
* BZ -
@ -55,12 +59,20 @@ public class MappingCreateRequest extends BaseRequest {
this.name = name;
}
public String getValue() {
return value;
public String getContext() {
return context;
}
public void setContext(String context) {
this.context = context;
}
public String getLocation() {
return location;
}
public void setValue(String value) {
this.value = value;
public void setLocation(String location) {
this.location = location;
}
public String getBz() {

@ -20,6 +20,8 @@ http {
sendfile on;
keepalive_timeout 65;
<#list services as item>
server {
listen 8888;
server_name localhost;
@ -28,13 +30,9 @@ http {
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /tzzdxxsb/ {
proxy_pass http://127.0.0.1:8081/;
<#list services.mappingList as mapping>
location /#{mapping.context} {
proxy_pass http://#{location};
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@ -51,10 +49,12 @@ http {
index index.html index.htm index.jsp index.do;
}
</#list>
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
</#list>
}

@ -68,11 +68,16 @@
<el-form-item label="名称" prop="name">
<el-input v-model="form.name" clearable size="small" placeholder="简要描述"></el-input>
</el-form-item>
<el-form-item label="路径" prop="value">
<el-form-item label="路径" prop="context">
<el-input v-model="form.value" clearable size="small" placeholder="字母数字组合">
<template slot="prepend">:{{form.port}}/</template>
</el-input>
</el-form-item>
<el-form-item label="地址" prop="location">
<el-input v-model="form.value" clearable size="small" placeholder="字母数字组合">
<template slot="prepend">http://</template>
</el-input>
</el-form-item>
<el-form-item label="备注" prop="bz">
<el-input type="textarea" v-model="form.bz" clearable size="small"
placeholder="备注信息"></el-input>
@ -97,7 +102,12 @@
<el-table-column
width="150px"
label="路径"
prop="value">
prop="context">
</el-table-column>
<el-table-column
width="150px"
label="地址"
prop="location">
</el-table-column>
<el-table-column
width="150px"

@ -31,7 +31,8 @@ public class MappingTest {
public void createMapping() {
MappingCreateRequest createRequest = new MappingCreateRequest();
createRequest.setName("测试");
createRequest.setValue("test");
createRequest.setContext("test");
createRequest.setLocation("test");
MappingCreateResponse mappingCreateResponse = mappingManager.create(createRequest, token);
assertTrue(!mappingCreateResponse.hasError());

Loading…
Cancel
Save

Powered by TurnKey Linux.