fix: nginx前后分离部署

This commit is contained in:
fit2cloud-chenyw 2022-02-16 16:10:39 +08:00
parent abe6f072c9
commit 995fe08298
10 changed files with 97 additions and 56 deletions

View File

@ -407,48 +407,74 @@
</dependencies> </dependencies>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<?m2e execute onConfiguration?>
<id>main-class-placement</id>
<phase>generate-resources</phase>
<configuration>
<target>
<move todir="src/main/resources/static">
<fileset dir="../frontend/dist">
<exclude name="*.html"/>
</fileset>
</move>
<move todir="src/main/resources/templates">
<fileset dir="../frontend/dist">
<include name="*.html"/>
</fileset>
</move>
<copy todir="src/main/resources/static/de-app">
<fileset dir="../mobile/dist">
<exclude name="*.html"/>
</fileset>
</copy>
<copy file="../mobile/dist/index.html" tofile="src/main/resources/templates/app.html" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
<profiles>
<profile>
<id>whole</id>
<properties>
<profiles.active>whole</profiles.active>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<?m2e execute onConfiguration?>
<id>main-class-placement</id>
<phase>generate-resources</phase>
<configuration>
<target>
<move todir="src/main/resources/static">
<fileset dir="../frontend/dist">
<exclude name="*.html"/>
</fileset>
</move>
<move todir="src/main/resources/templates">
<fileset dir="../frontend/dist">
<include name="*.html"/>
</fileset>
</move>
<copy todir="src/main/resources/static/de-app">
<fileset dir="../mobile/dist">
<exclude name="*.html"/>
</fileset>
</copy>
<copy file="../mobile/dist/index.html" tofile="src/main/resources/templates/app.html" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>stage</id>
<properties>
<profiles.active>stage</profiles.active>
</properties>
</profile>
</profiles>
<repositories> <repositories>
<repository> <repository>
<id>pentaho-public</id> <id>pentaho-public</id>

View File

@ -53,7 +53,7 @@ public class IndexController {
String url; String url;
if (CodingUtil.isNumeric(index)) { if (CodingUtil.isNumeric(index)) {
url = panelLinkService.getUrlByIndex(Long.parseLong(index)); url = panelLinkService.getUrlByIndex(Long.parseLong(index));
}else { } else {
url = panelLinkService.getUrlByUuid(index); url = panelLinkService.getUrlByUuid(index);
} }
HttpServletResponse response = ServletUtils.response(); HttpServletResponse response = ServletUtils.response();
@ -65,8 +65,6 @@ public class IndexController {
} }
} }
@GetMapping("/tempMobileLink/{id}/{token}") @GetMapping("/tempMobileLink/{id}/{token}")
public void tempMobileLink(@PathVariable("id") String id, @PathVariable("token") String token) { public void tempMobileLink(@PathVariable("id") String id, @PathVariable("token") String token) {
String url = "/#preview/" + id; String url = "/#preview/" + id;

View File

@ -8,7 +8,6 @@ import io.dataease.base.mapper.PanelGroupMapper;
import io.dataease.base.mapper.PanelLinkMapper; import io.dataease.base.mapper.PanelLinkMapper;
import io.dataease.base.mapper.PanelLinkMappingMapper; import io.dataease.base.mapper.PanelLinkMappingMapper;
import io.dataease.base.mapper.ext.ExtPanelLinkMapper; import io.dataease.base.mapper.ext.ExtPanelLinkMapper;
import io.dataease.commons.exception.DEException;
import io.dataease.commons.utils.AuthUtils; import io.dataease.commons.utils.AuthUtils;
import io.dataease.commons.utils.CodingUtil; import io.dataease.commons.utils.CodingUtil;
import io.dataease.commons.utils.ServletUtils; import io.dataease.commons.utils.ServletUtils;
@ -20,6 +19,7 @@ import io.dataease.dto.panel.link.GenerateDto;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -27,7 +27,6 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
import java.util.Optional;
@Service @Service
public class PanelLinkService { public class PanelLinkService {
@ -36,6 +35,9 @@ public class PanelLinkService {
private static final String USERPARAM = "&user="; private static final String USERPARAM = "&user=";
private static final String SHORT_URL_PREFIX = "/link/"; private static final String SHORT_URL_PREFIX = "/link/";
@Value("${server.servlet.context-path}")
private String contextPath;
@Resource @Resource
private PanelLinkMapper mapper; private PanelLinkMapper mapper;
@Resource @Resource
@ -60,7 +62,7 @@ public class PanelLinkService {
panelLinkMappingMapper.updateByExampleSelective(mapping, example); panelLinkMappingMapper.updateByExampleSelective(mapping, example);
} }
private PanelLinkExample example(String panelLinkId, Long userId){ private PanelLinkExample example(String panelLinkId, Long userId) {
PanelLinkExample example = new PanelLinkExample(); PanelLinkExample example = new PanelLinkExample();
example.createCriteria().andResourceIdEqualTo(panelLinkId).andUserIdEqualTo(userId); example.createCriteria().andResourceIdEqualTo(panelLinkId).andUserIdEqualTo(userId);
return example; return example;
@ -88,18 +90,18 @@ public class PanelLinkService {
private PanelLink findOne(String resourceId) { private PanelLink findOne(String resourceId) {
PanelLinkExample example = new PanelLinkExample(); PanelLinkExample example = new PanelLinkExample();
example.createCriteria().andResourceIdEqualTo(resourceId).andUserIdIsNull(); example.createCriteria().andResourceIdEqualTo(resourceId).andUserIdIsNull();
List<PanelLink> list = mapper.selectByExample(example); List<PanelLink> list = mapper.selectByExample(example);
return CollectionUtils.isNotEmpty(list) ? list.get(0) : null; return CollectionUtils.isNotEmpty(list) ? list.get(0) : null;
} }
public PanelLink findOne(String resourceId, Long userId) { public PanelLink findOne(String resourceId, Long userId) {
if(userId == null){ if (userId == null) {
return findOne(resourceId); return findOne(resourceId);
} }
List<PanelLink> panelLinks = mapper.selectByExample(example(resourceId, userId)); List<PanelLink> panelLinks = mapper.selectByExample(example(resourceId, userId));
if(CollectionUtils.isNotEmpty(panelLinks)){ if (CollectionUtils.isNotEmpty(panelLinks)) {
return panelLinks.get(0); return panelLinks.get(0);
}else { } else {
return null; return null;
} }
} }
@ -152,8 +154,8 @@ public class PanelLinkService {
private String buildLinkParam(PanelLink link) { private String buildLinkParam(PanelLink link) {
String linkParam = encrypt(link.getResourceId()); String linkParam = encrypt(link.getResourceId());
if(link.getUserId() != null){ if (link.getUserId() != null) {
linkParam = linkParam+ USERPARAM + link.getUserId().toString(); linkParam = linkParam + USERPARAM + link.getUserId().toString();
} }
return linkParam; return linkParam;
} }
@ -172,7 +174,8 @@ public class PanelLinkService {
public Boolean validateHeads(PanelLink panelLink) throws Exception { public Boolean validateHeads(PanelLink panelLink) throws Exception {
HttpServletRequest request = ServletUtils.request(); HttpServletRequest request = ServletUtils.request();
String token = request.getHeader("LINK-PWD-TOKEN"); String token = request.getHeader("LINK-PWD-TOKEN");
if (!panelLink.getEnablePwd() || StringUtils.isEmpty(token) || StringUtils.equals("undefined", token) || StringUtils.equals("null", token)) { if (!panelLink.getEnablePwd() || StringUtils.isEmpty(token) || StringUtils.equals("undefined", token)
|| StringUtils.equals("null", token)) {
String resourceId = panelLink.getResourceId(); String resourceId = panelLink.getResourceId();
String pwd = "dataease"; String pwd = "dataease";
String tk = JWTUtils.signLink(resourceId, panelLink.getUserId(), pwd); String tk = JWTUtils.signLink(resourceId, panelLink.getUserId(), pwd);
@ -181,7 +184,8 @@ public class PanelLinkService {
httpServletResponse.setHeader("LINK-PWD-TOKEN", tk); httpServletResponse.setHeader("LINK-PWD-TOKEN", tk);
return false; return false;
} }
if (StringUtils.isEmpty(panelLink.getPwd())) return false; if (StringUtils.isEmpty(panelLink.getPwd()))
return false;
return JWTUtils.verifyLink(token, panelLink.getResourceId(), panelLink.getUserId(), panelLink.getPwd()); return JWTUtils.verifyLink(token, panelLink.getResourceId(), panelLink.getUserId(), panelLink.getPwd());
} }
@ -218,7 +222,7 @@ public class PanelLinkService {
List<PanelLinkMapping> mappings = panelLinkMappingMapper.selectByExample(example); List<PanelLinkMapping> mappings = panelLinkMappingMapper.selectByExample(example);
PanelLinkMapping mapping = mappings.get(0); PanelLinkMapping mapping = mappings.get(0);
String uuid = mapping.getUuid(); String uuid = mapping.getUuid();
return SHORT_URL_PREFIX + (StringUtils.isBlank(uuid) ? mapping.getId() : uuid); return contextPath + SHORT_URL_PREFIX + (StringUtils.isBlank(uuid) ? mapping.getId() : uuid);
} }
public String getUrlByIndex(Long index) { public String getUrlByIndex(Long index) {

View File

@ -0,0 +1 @@
server.servlet.context-path=/de-api

View File

@ -0,0 +1 @@
server.servlet.context-path=

View File

@ -1,3 +1,4 @@
spring.profiles.active=@profiles.active@
spring.application.name=dataease spring.application.name=dataease
server.port=8081 server.port=8081

View File

@ -4,5 +4,5 @@ NODE_ENV = production
ENV = 'staging' ENV = 'staging'
# base api # base api
VUE_APP_BASE_API = '/stage-api' VUE_APP_BASE_API = '/de-api/'

View File

@ -14,7 +14,7 @@ import Cookies from 'js-cookie'
const getTimeOut = () => { const getTimeOut = () => {
let time = 10 let time = 10
const url = '/system/requestTimeOut' const url = process.env.VUE_APP_BASE_API + 'system/requestTimeOut'
const xhr = new XMLHttpRequest() const xhr = new XMLHttpRequest()
xhr.onreadystatechange = () => { xhr.onreadystatechange = () => {
if (xhr.readyState === 4 && xhr.status === 200) { if (xhr.readyState === 4 && xhr.status === 200) {

8
mobile/.env.staging Normal file
View File

@ -0,0 +1,8 @@
NODE_ENV = production
# just a flag
ENV = 'staging'
# base api
VUE_APP_BASE_API = '/de-api/'

View File

@ -5,6 +5,8 @@
"scripts": { "scripts": {
"serve": "npm run dev:h5", "serve": "npm run dev:h5",
"build": "npm run build:h5", "build": "npm run build:h5",
"build:stage": "npm run build:h5:stage",
"build:h5:stage": "cross-env NODE_ENV=production UNI_PLATFORM=h5 UNI_OUTPUT_DIR=dist vue-cli-service uni-build --mode staging",
"build:app-plus": "cross-env NODE_ENV=production UNI_PLATFORM=app-plus vue-cli-service uni-build", "build:app-plus": "cross-env NODE_ENV=production UNI_PLATFORM=app-plus vue-cli-service uni-build",
"build:custom": "cross-env NODE_ENV=production uniapp-cli custom", "build:custom": "cross-env NODE_ENV=production uniapp-cli custom",
"build:h5": "cross-env NODE_ENV=production UNI_PLATFORM=h5 UNI_OUTPUT_DIR=dist vue-cli-service uni-build", "build:h5": "cross-env NODE_ENV=production UNI_PLATFORM=h5 UNI_OUTPUT_DIR=dist vue-cli-service uni-build",