Unable to serve a static web page using Spark java framework

45 views Asked by At

I have the below code - which is configured to serve static web page within the package (src/main/resources/public)

Which is not working and i dont see any exception in the logs as well

 public void startRestServer() {
        try {
            port(serverPort);
//            staticFiles.location(System.getProperty("user.dir") + "/src/main/resources/public/");
            staticFiles.location("/public");
            connectionPool = SQLiteConnectionPool.getInstance(fileServerLocation, MIN_THREADS, MAX_THREADS, TIMEOUT);
            staticFiles.externalLocation(this.fileServerLocation);
            init();
            awaitInitialization();
            loadRestApiServices();
            LOGGER.debug(String.format("REST services started :: http://%s:%s%s/",
                    InetAddress.getLocalHost().getHostAddress(), serverPort, uriPath));
        } catch (Exception e) {
            LOGGER.error("REST services failed to start", e);
        }
    }

I have API path configured below

public void loadRestApiServices() {
        UploadService uploadService = new UploadServiceImpl();
        path(RestController.uriPath, () -> {
            before("/*", (req, res) -> LOGGER.info("Received api call"));

            get("/greet", (req, res) -> {
                return "Hello Work !";
            });

            post("/upload", (req, res) -> {
                JSONObject jsonObject = new JSONObject(req.body());
                uploadService.uploadCustomPlugin(jsonObject);
                return null;
            });

            after((req, res) -> res.header("Content-Encoding", "gzip"));

        });

enter image description here

Expected result:

I want it to serve the index.html to user - which is basically a post form, to upload files

0

There are 0 answers