Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(v2): Integrate middleware and htmlfallback middlewear usage #1891

Merged
merged 5 commits into from
Oct 29, 2024

Conversation

ErKeLost
Copy link
Member

@ErKeLost ErKeLost commented Oct 28, 2024

Integrating farm dev server has all middleware functions and the impact of appType on configuring spa, mpa and custom fields functions

The following is a brief explanation of the core points of this pr, only about the appType function

image

The functions of each part of the middleware in the following order are as follows

  • corsMiddleware: Allowing the server to control which cross-domain requests can be accepted by the browser
  • proxyMiddleware: Mainly used to process proxy requests in the development server
  • publicPathMiddleware: Routing control to be used to handle static resource and URL redirects
  • adapterViteMiddleware: A middleware used to process resource files in Vite development mode. Its main purpose is to ensure that certain resources (such as images or fonts) are compiled and provided correctly in development mode
  • lazyComplationMiddleware: Handle routing lazy loading middleware
  • resourceMiddleware: Handle all resouce to change browser url
  • publicMiddleware: Is a middleware used to process static resources, mainly used to provide static files in public directories in the development server
  • notFoundMiddleware: return 404
  • htmlFallbackMiddleware: Returns different html benchmark resources for different source and apptype return values

The following functional areas are divided into two points

  1. All middleware is selected by default
  2. If apptype is set to custom, htmlFallbackMiddleware and notFoundMiddleware will not be used

if the appType is set to spa, but the user passes in multiple inputs at this time

import { defineConfig } from "@farmfe/core";
import path from "path";

export default defineConfig({
  compilation: {
    input: {
      index: path.resolve(__dirname, "index.html"),
      base: path.resolve(__dirname, 'base.html'),
      about: path.resolve(__dirname, 'about.html'),
    },
  },
  server: {
    appType: "mpa",
  },
});

Then the following paths are valid as

if the appType is set to spa,

effective:
localhost:3000
localhost:3000/
localhost:3000/123456
localhost:3000/index.html
localhost:3000/base.html
localhost:3000/about.html

if the appType is set to mpa

this localhost:3000/123456 will be not effective return undefined

if the appType is set to custom

    if (appType === 'spa' || appType === 'mpa') {
      this.middlewares.use(htmlFallbackMiddleware(this));

      this.middlewares.use(notFoundMiddleware());
    }

Then we will not control the situation where middlewareMode is currently only set to true in the user's functional scenario for returning html

Subsequent pr will analyze all scenarios and functions of each middleware in detail

Copy link

changeset-bot bot commented Oct 28, 2024

🦋 Changeset detected

Latest commit: 5c4e780

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

💥 An error occurred when fetching the changed packages and changesets in this PR
Some errors occurred when validating the changesets config:
The package or glob expression "farm-docs" is specified in the `ignore` option but it is not found in the project. You may have misspelled the package name or provided an invalid glob expression. Note that glob expressions must be defined according to https://www.npmjs.com/package/micromatch.

@ErKeLost ErKeLost changed the title chore: Integrate middleware and htmlfallback middlewear usage chore(v2): Integrate middleware and htmlfallback middlewear usage Oct 28, 2024
@@ -4,7 +4,7 @@
"biome.enabled": true,
"editor.defaultFormatter": "biomejs.biome",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "vscode.typescript-language-features"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use biome to format code

@ErKeLost ErKeLost merged commit b327dd1 into farm-fe:v2-dev Oct 29, 2024
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants