Deployment
Midway Hooks supports Api Server and integration.
Api Server deployment
For more information about how to deploy Api Server, see Start and deploy Api Server.
If you use a single file deployment, you can refer to the example: hooks-api-bundle-starter
Integrated deployment
The integrated construction product includes the front and back ends, which can be divided into the following categories according to the difficulty of deployment.
- The front and back ends are deployed on the same server, and the back end hosts HTML & static resources & provides interfaces
- Static resources are deployed to CDN, backend hosting HTML & providing interfaces
- Static resources are deployed to CDN,HTML is hosted by a separate service (CDN / Nginx / etc.), and the backend only provides interfaces.
Next, I will introduce how the three deployment modes land, their advantages and existing problems.
The front and back ends are deployed on the same server
This is the default deployment mode for full stack suites.
Advantages: The simplest, upload the packaged product directly to the server, and provide services after startup Weaknesses:
- Backend services need to process & send files
- Static resources are not located in CDN, and the access speed of different regions is unstable.
The overall deployment architecture is shown in the figure:
Static resources are deployed to CDN, backend hosting HTML & providing interfaces
This is also the current front-end mainstream deployment mode.
Advantages:
- Static resources are hosted by CDN to ensure user access speed.
- The back end hosts HTML to ensure that the returned HTML file is up to date
Weaknesses:
- The backend still needs to host HTML, still needs to process & send files, and the page cannot be accessed if the service goes down.
The overall access architecture is shown in the figure:
Specify a static resource public domain name
You can specify the public domain name of static resources by setting the site. base
option in midway.config.ts
.
import react from '@vitejs/plugin-react';
import { defineConfig } from '@midwayjs/hooks-kit';
export default defineConfig({
vite: {
plugins: [react()]
base: 'https://cdn.example.com',
},
});
When accessing the page, the static resource will point to the address of the CDN.
Deploy static files
In a full stack suite project, the default build directory is dist, where dist/_clients
is the frontend static resource directory.
As follows:
dist
├── _client
│ ├── assets