mirror of https://github.com/halo-dev/halo
Allow customization of admin path
parent
f7057db030
commit
8463a3f31e
|
@ -3,7 +3,6 @@ package run.halo.app.controller.content;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import run.halo.app.config.properties.HaloProperties;
|
||||
import run.halo.app.exception.ServiceException;
|
||||
|
@ -13,6 +12,7 @@ import run.halo.app.model.support.HaloConst;
|
|||
import run.halo.app.service.OptionService;
|
||||
import run.halo.app.service.UserService;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -25,6 +25,16 @@ import java.io.IOException;
|
|||
@Controller
|
||||
public class MainController {
|
||||
|
||||
/**
|
||||
* Index redirect uri.
|
||||
*/
|
||||
private final static String INDEX_REDIRECT_URI = "index.html";
|
||||
|
||||
/**
|
||||
* Install redirect uri.
|
||||
*/
|
||||
private final static String INSTALL_REDIRECT_URI = INDEX_REDIRECT_URI + "#install";
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
private final OptionService optionService;
|
||||
|
@ -37,9 +47,10 @@ public class MainController {
|
|||
this.haloProperties = haloProperties;
|
||||
}
|
||||
|
||||
@GetMapping("{permlink}")
|
||||
public String admin(@PathVariable(name = "permlink") String permlink) {
|
||||
return "redirect:/" + permlink + "/index.html";
|
||||
@GetMapping("${halo.admin-path:admin}")
|
||||
public void admin(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
String adminIndexRedirectUri = StringUtils.appendIfMissing(this.haloProperties.getAdminPath(), "/") + INDEX_REDIRECT_URI;
|
||||
response.sendRedirect(adminIndexRedirectUri);
|
||||
}
|
||||
|
||||
@GetMapping("version")
|
||||
|
@ -49,8 +60,9 @@ public class MainController {
|
|||
}
|
||||
|
||||
@GetMapping("install")
|
||||
public String installation() {
|
||||
return "redirect:" + haloProperties.getAdminPath() + "/index.html#install";
|
||||
public void installation(HttpServletResponse response) throws IOException {
|
||||
String installRedirectUri = StringUtils.appendIfMissing(this.haloProperties.getAdminPath(), "/") + INSTALL_REDIRECT_URI;
|
||||
response.sendRedirect(installRedirectUri);
|
||||
}
|
||||
|
||||
@GetMapping("avatar")
|
||||
|
@ -76,4 +88,5 @@ public class MainController {
|
|||
response.sendRedirect(favicon);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package run.halo.app.controller.core;
|
||||
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.web.ErrorProperties;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
|
@ -68,7 +69,11 @@ public class CommonController extends AbstractErrorController {
|
|||
public String handleError(HttpServletRequest request, HttpServletResponse response, Model model) {
|
||||
HttpStatus status = getStatus(request);
|
||||
|
||||
log.error("Error path: [{}], status: [{}]", getErrorPath(), status);
|
||||
log.error("Request URL: [{}], URI: [{}], Request Method: [{}], IP: [{}]",
|
||||
request.getRequestURL(),
|
||||
request.getRequestURI(),
|
||||
request.getMethod(),
|
||||
ServletUtil.getClientIP(request));
|
||||
|
||||
handleCustomException(request);
|
||||
|
||||
|
|
|
@ -16,6 +16,11 @@ import java.util.List;
|
|||
@Component
|
||||
public class RandomMethod implements TemplateMethodModelEx {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param configuration injected by spring.
|
||||
*/
|
||||
public RandomMethod(Configuration configuration) {
|
||||
configuration.setSharedVariable("randomMethod", this);
|
||||
}
|
||||
|
@ -29,6 +34,9 @@ public class RandomMethod implements TemplateMethodModelEx {
|
|||
*/
|
||||
@Override
|
||||
public Object exec(List arguments) throws TemplateModelException {
|
||||
if (arguments.size() != 2) {
|
||||
throw new TemplateModelException("Wrong arguments! 2 arguments are needed");
|
||||
}
|
||||
SimpleNumber argOne = (SimpleNumber) arguments.get(0);
|
||||
SimpleNumber argTwo = (SimpleNumber) arguments.get(1);
|
||||
int start = argOne.getAsNumber().intValue();
|
||||
|
|
Loading…
Reference in New Issue