X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fric%2Fportal%2Fdashboard%2Fcontroller%2FHtml5PathsController.java;fp=webapp-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fric%2Fportal%2Fdashboard%2Fcontroller%2FHtml5PathsController.java;h=abe3b16fc55be52a3ded84e2948e0f721f35e595;hb=09df6d1bb8687f6f7970efbcac9bd3dc7b9503bb;hp=0000000000000000000000000000000000000000;hpb=4343a59bf8db708600c9c6a712aa01bbb437db00;p=portal%2Fric-dashboard.git diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/Html5PathsController.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/Html5PathsController.java new file mode 100644 index 00000000..abe3b16f --- /dev/null +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/Html5PathsController.java @@ -0,0 +1,59 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2019 AT&T Intellectual Property and Nokia + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================LICENSE_END=================================== + */ +package org.oransc.ric.portal.dashboard.controller; + +import java.lang.invoke.MethodHandles; + +import javax.servlet.http.HttpServletRequest; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +/** + * Listens for requests to known Angular routes. + */ +@Controller +public class Html5PathsController { + + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + /** + * Forwards the browser to the index (main) page upon request of a known route. + * This unfortunately requires duplication of the Angular route strings in the + * path mappings on this method. Could switch to a regex pattern instead someday + * if the routes change too often. + * + * https://stackoverflow.com/questions/44692781/configure-spring-boot-to-redirect-404-to-a-single-page-app + * + * @param request + * HttpServletRequest + * @return Forward directive to index.html + */ + @RequestMapping(method = { RequestMethod.OPTIONS, RequestMethod.GET }, // + path = { "/catalog", "/control", "/stats", "/user" }) + public String forwardAngularRoutes(HttpServletRequest request) { + logger.debug("forwardAngularRoutes: {}", request.getRequestURI()); + return "forward:/index.html"; + } + +}