001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.petstore.rest;
018
019import java.util.*;
020
021import org.apache.juneau.http.*;
022import org.apache.juneau.rest.server.*;
023import org.apache.juneau.rest.server.servlet.*;
024import org.apache.juneau.rest.server.staticfile.*;
025
026/**
027 * Petstore React SPA demo — serves the no-build single-page React UI from the core classpath.
028 *
029 * <p>
030 * Composes {@link StaticFilesMixin} to serve {@code /static/*} from the importer's classpath: the file
031 * {@code static/petstore-ui.html} is reachable at {@code GET /petstore-ui/static/petstore-ui.html}.  The HTML
032 * loads the vendored React + ReactDOM bundles ({@code static/vendor/}) and uses {@code fetch()} against {@code /petstore/pets} to demonstrate the headless-JSON +
033 * decoupled-SPA pattern alongside the server-rendered HTML-doc UI.
034 *
035 * <p>
036 * The app is also served at the resource root ({@code GET /petstore-ui}), so the console can embed and link it without
037 * knowing the static mount.
038 *
039 * <p>
040 * Lives in {@code juneau-petstore-core} so both the Jetty and Spring Boot deployments inherit it for free.
041 *
042 * <h5 class='section'>See Also:</h5><ul>
043 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauPetstore">juneau-petstore</a>
044 * </ul>
045 */
046@Rest(
047   path="/petstore-ui",
048   title="Petstore — React SPA demo",
049   description="No-build single-page React UI loaded as static classpath resource; calls /petstore/* over fetch().",
050   mixins=StaticFilesMixin.class
051)
052@SuppressWarnings({
053   "java:S110" // Inheritance depth acceptable for example/demo code
054})
055public class PetstoreUiResource extends BasicRestServlet {
056
057   private static final long serialVersionUID = 1L;
058
059   /**
060    * [GET /] &mdash; the single-page app.
061    *
062    * @param req The current request.
063    * @param locale The request locale.
064    * @return The app's HTML page.
065    */
066   @RestGet(path="/", summary="The React app", swagger=@OpSwagger(ignore=true))
067   public HttpResource app(RestRequest req, Locale locale) {
068      return StaticFilesMixin.resolveStaticFile(req, "petstore-ui.html", locale);
069   }
070}