diff --git a/src/main/java/app/handler/RegisterWithPost.java b/src/main/java/app/handler/RegisterWithPost.java index f1844c3a1..066683b9b 100644 --- a/src/main/java/app/handler/RegisterWithPost.java +++ b/src/main/java/app/handler/RegisterWithPost.java @@ -11,7 +11,7 @@ import web.filter.authentication.UserRole; import web.handler.SingleArgHandler; import web.response.HandlerResponse; -import web.response.StaticViewResponse; +import web.response.RedirectResponse; public class RegisterWithPost extends SingleArgHandler { private static final Logger log = LoggerFactory.getLogger(RegisterWithPost.class); @@ -27,6 +27,6 @@ public HandlerResponse handle(QueryParameters params) { String password = params.getQueryValue("password").orElseThrow(()-> new ServiceException(ErrorCode.MISSING_REGISTER_TOKEN, "password required")); Database.addUser(new User(password, nickname, email, UserRole.MEMBER.toString())); log.info("Registered - password:{}, nickname:{}, email:{}", password, nickname, email); - return StaticViewResponse.of("/login"); + return RedirectResponse.to("/login"); } } diff --git a/src/main/java/config/AppConfig.java b/src/main/java/config/AppConfig.java index d98b5eb29..64c8413d1 100644 --- a/src/main/java/config/AppConfig.java +++ b/src/main/java/config/AppConfig.java @@ -18,6 +18,7 @@ import web.dispatch.argument.resolver.HttpRequestResolver; import web.dispatch.argument.resolver.QueryParamsResolver; import web.filter.*; +import web.handler.DefaultViewHandler; import web.handler.StaticContentHandler; import web.handler.WebHandler; import web.renderer.DynamicViewRenderer; @@ -88,7 +89,8 @@ public List webHandlerList() { registerWithPost(), loginWithPost(), logoutWithPost(), - homeHandler()) + homeHandler(), + defaultViewHandler()) ); } @@ -99,6 +101,10 @@ public StaticContentHandler staticContentHandler() { ); } + public DefaultViewHandler defaultViewHandler(){ + return getOrCreate("defaultViewHandler", DefaultViewHandler::new); + } + public RegisterWithGet registerWithGet() { return getOrCreate( "registerWithGet", diff --git a/src/main/java/web/handler/DefaultViewHandler.java b/src/main/java/web/handler/DefaultViewHandler.java new file mode 100644 index 000000000..88cd4af40 --- /dev/null +++ b/src/main/java/web/handler/DefaultViewHandler.java @@ -0,0 +1,43 @@ +package web.handler; + +import config.VariableConfig; +import exception.ErrorException; +import http.HttpMethod; +import http.HttpStatus; +import http.request.HttpRequest; +import web.response.DynamicViewResponse; +import web.response.HandlerResponse; + +import java.io.File; +import java.util.List; + +public class DefaultViewHandler implements DefaultHandler{ + private final List roots = VariableConfig.DYNAMIC_RESOURCE_ROOTS; + private final HttpMethod method = HttpMethod.GET; + + @Override + public String getPath() { + throw new ErrorException("DynamicViewHandler::getPath should not be called"); + } + + @Override + public HttpMethod getMethod() { + return this.method; + } + @Override + public boolean checkEndpoint(HttpMethod method, String path) { + if(!method.equals(this.method)) return false; + return roots.stream().anyMatch(root ->{ + File requestedFile = new File(root + path); + String indexFilePath = path + (path.endsWith("/") ? "index.html" : "/index.html"); + File indexFile = new File(root + indexFilePath); + return (requestedFile.exists() && requestedFile.isFile()) || (indexFile.exists() && indexFile.isFile()); + }); + } + + @Override + public HandlerResponse handle(HttpRequest request) { + String path = request.getPath() + (request.getPath().endsWith("/") ? "index.html" : "/index.html"); + return DynamicViewResponse.of(HttpStatus.OK, path); + } +} diff --git a/src/main/resources/static/article/index.html b/src/main/resources/templates/article/index.html similarity index 60% rename from src/main/resources/static/article/index.html rename to src/main/resources/templates/article/index.html index 6d2c8eeef..41de15965 100644 --- a/src/main/resources/static/article/index.html +++ b/src/main/resources/templates/article/index.html @@ -3,24 +3,12 @@ - - + +
-
- - -
+ {{> /layout/header.html}}

게시글 작성

diff --git a/src/main/resources/static/comment/index.html b/src/main/resources/templates/comment/index.html similarity index 60% rename from src/main/resources/static/comment/index.html rename to src/main/resources/templates/comment/index.html index 35df2b252..eca5bb38f 100644 --- a/src/main/resources/static/comment/index.html +++ b/src/main/resources/templates/comment/index.html @@ -3,24 +3,12 @@ - - + +
-
- - -
+ {{> /layout/header.html}}

댓글 작성

diff --git a/src/main/resources/templates/layout/error-popup.html b/src/main/resources/templates/layout/error-popup.html new file mode 100644 index 000000000..7b9516f8a --- /dev/null +++ b/src/main/resources/templates/layout/error-popup.html @@ -0,0 +1,121 @@ + + +
+
+
알림
+
+
+ +
+
+
+ + diff --git a/src/main/resources/templates/layout/header.html b/src/main/resources/templates/layout/header.html index 0b5bfd3be..678006c49 100644 --- a/src/main/resources/templates/layout/header.html +++ b/src/main/resources/templates/layout/header.html @@ -4,7 +4,10 @@
    {{#if1 isLoginUser}}
  • - 닉네임: {{userNickname}} + 닉네임: {{userNickname}} +
  • +
  • + 글쓰기
  • diff --git a/src/main/resources/static/login/index.html b/src/main/resources/templates/login/index.html similarity index 65% rename from src/main/resources/static/login/index.html rename to src/main/resources/templates/login/index.html index 7c87ea590..481c62717 100644 --- a/src/main/resources/static/login/index.html +++ b/src/main/resources/templates/login/index.html @@ -3,27 +3,15 @@ - - + +
    -
    - - -
    + {{> /layout/header.html}}

    로그인

    - +

    이메일

    로그인
    + {{> /layout/error-popup.html}} diff --git a/src/main/resources/static/mypage/index.html b/src/main/resources/templates/mypage/index.html similarity index 78% rename from src/main/resources/static/mypage/index.html rename to src/main/resources/templates/mypage/index.html index 7ab744957..6f7db6ee4 100644 --- a/src/main/resources/static/mypage/index.html +++ b/src/main/resources/templates/mypage/index.html @@ -3,24 +3,13 @@ - - + +
    -
    - - -
    + {{> /layout/header.html}} +

    마이페이지

    @@ -74,8 +63,10 @@

    마이페이지

    변경사항 저장 - -
    + +
    +
+ {{> /layout/error-popup.html}} diff --git a/src/main/resources/static/registration/index.html b/src/main/resources/templates/registration/index.html similarity index 71% rename from src/main/resources/static/registration/index.html rename to src/main/resources/templates/registration/index.html index 4222dd38a..83ee68c5a 100644 --- a/src/main/resources/static/registration/index.html +++ b/src/main/resources/templates/registration/index.html @@ -3,27 +3,15 @@ - - + +
-
- - -
+ {{> /layout/header.html}}

회원가입

-
+

이메일

회원가입
+ {{> /layout/error-popup.html}}