/demo-monorepo-vertx-react

How to start a backend with Vertx and a React frontend with ViteJS

Primary LanguageJava

Demo Vertx + React

How to start a backend with Vertx and a React frontend with ViteJS.

References

Prerequisite

Install

git clone git@github.com:ccreusat/demo-monorepo-vertx-react.git

Install root and frontend dependencies:

yarn && yarn start

Backend

You can start server on Port 3001 with Gradle:

yarn server

For this example, /api/message will send this message:

Hello React from Vert.x!

You can check if route is working fine with:

  • HTTPie in your terminal
http :3001/api/message
  • Using route in your browser
http://localhost:3001/api/message

Hello React from Vert.x!

Frontend

You can start React app on Port 3000 :

yarn client

You should see Hello React from Vert.x! inside your client app.

Server Proxy

ViteJS Server will listen the Port 3001 on /api route:

server: {
    proxy: {
      "/api": "http://localhost:3001",
    },
    host: "0.0.0.0",
    port: 3000,
    open: true,
}

Server Options

Build

The build task will create the frontend application and add the bundle to: build/classes/java/main/webroot

yarn server

Browse to http://localhost:3001 and you should see the build version.