The new generation of JOJ Frontend. Built with Vite.
- node.js >= 16
- pnpm
This frontend project uses submodule to synchronize OpenAPI interfaces with the backend.
Run the following commands in the project directory.
git submodule init
git submodule update
This will pull the openapi.json
into directory openapi
.
If the backend updated openapi.json
, you need to pull the latest version by:
cd openapi
git checkout xxx # If you want a different branch
git pull
Please install pnpm
first. This project uses pnpm
as package manager. You can modify your registry to boost downloading.
Install dependencies:
$ pnpm install
After that, you can pick a following approach you prefer to start developing.
Run the frontend locally, while connecting to the backend deployed on a staging server.
$ pnpm dev:staging
Now the frontend is running on localhost:5173
.
We need some extra setup to overcome the same-origin policy.
- Install whistle to proxy the local frontend to the staging domain.
- Start whistle by executing
w2 start
and the whistle server shall be running onlocalhost:8899
. - Visit
localhost:8899
and add a single rule:
nichujie.xyz 127.0.0.1:5173
Whistle, as a proxy server, now proxies nichujie.xyz
to 127.0.0.1:5173
.
Visiting nichujie.xyz
in your browser now will hit the staging server, rather than your local frontend. This is becuase we have only setup the proxy server, but have not configure our browser to use that server.
Install SwitchyOmega if you are using chrome. (For other browsers please refer to docs). And in settings of SwitchyOmega, have such config:
Remember to switch on the proxy profile in the dropdown menu of the plugin.
Now you can visit nichujie.xyz
in your browser to access your local frontend server. After you save your code locally, the webpage shall reload automatically.
Staging is a type of environment that lies between development (local) and production (online). Developers don't need to setup the backend services (database, message queue, server...), but just bring up the frontend and connect to the backend on a remote server.
You can also run the backend on your local machine. Please check joj-deploy-lite to setup the backend in one command.
Then, start the local frontend:
$ pnpm dev
The frontend will run on 127.0.0.1:5173
by default. All requests to the backend are proxied to 127.0.0.1:34765
.
In this mode, signing in by OAuth2 is difficult. You are recommended to use the simple
Note: Please always use 127.0.0.1:5173 instead of localhost:5173 to avoid issues about same-site cookie policies.
TODO: In the future, we may setup a staging development environment which runs frontend locally, while connecting to online (production) backend service.
To build and deploy, run:
$ pnpm build
pnpm gen:api
- generate API client with localopenapi.json
.pnpm gen:api-dev
- generate API client withopenapi.json
fetched from local backend server.pnpm gen:api-staging
- generate API client with localopenapi.json
fetched from staging (remote) backend server.
pnpm dev
- runpnpm gen:api-dev
, and start a dev server.pnpm dev:staging
- runpnpm gen:api-staging
, and start a dev server.
pnpm build
- build for production. The generated files will be on thedist
folder. (need to generate API client first)pnpm preview
- locally preview the production build.
pnpm test
- run unit and integration tests related to changed files based on git.pnpm test:ci
- run all unit and integration tests in CI mode.pnpm test:e2e
- run all e2e tests with the Cypress Test Runner.pnpm test:e2e:headless
- run all e2e tests headlessly.pnpm format
- format all files with Prettier.pnpm lint
- runs TypeScript, ESLint and Stylelint.pnpm validate
- runslint
,test:ci
andtest:e2e:ci
.
To learn more about this project, please refer to this site.
Please refer to this doc for our workflow.