This chapter answers only two things: how frontend and backend integrate and where configuration is changed. Key values are always represented by placeholders/“ciphertext”; shared environment addresses already committed to the repository are listed at their original values, to identify “accidental connections to the shared environment” — do not treat them as local machine addresses.

Local ports follow the repository’s dev configuration; shared environment/production follows deployment parameters.

1. Understand the Integration Model First

1.1 Browsers Do Not Connect Directly to the Java Backend

flowchart LR
  B["Browser / InnoApp"] -->|"same-origin /api or /api-h5"| N["Next.js BFF"]
  N -->|"server-side fetch + HOOX-AUTH"| J["CMS / CAP REST"]
  J -->|"SDK / REST"| E["SMP / GOMS / aPaaS / ROMA / payment, etc."]

The reasons for this design (which are also code facts):

  • The BFF converts the NextAuth/CST login state into the HOOX-AUTH, token, and base-params recognized by the backend.
  • Backend addresses and the RSA private key are placed only in Node server-side environment variables and are not exposed to the browser.
  • The browser only faces same-origin addresses, so the backend does not need to enable CORS.
  • The BFF can uniformly handle CSRF, CAPTCHA, response normalization, and file stream processing.

Do not let the browser request 8343/8346 directly “to make things faster”: this bypasses the BFF’s authentication, whitelist, IP/language headers, and error handling at the same time, and also requires additional CORS handling.

1.2 Do Not Mix the Three Types of Addresses

TypeExampleWho can see itNotes
Browser access addressNEXTAUTH_URL, NEXT_PUBLIC_H5_SERVICE_ADDRESS, NEXT_PUBLIC_APP_SERVICE_ADDRESSBrowser/externalMust be an address accessible from the user’s browser; do not use the container’s internal IP
BFF-to-backend addressCMS_REST_API_BASEPATH, CAP_REST_API_BASEPATH, CAP_SERVER_API_BASEPATHNode server onlyFor local integration, use 127.0.0.1:<local port>; for the shared environment, use the actual service address
Backend-to-dependency addressSMP_OPEN_REST_URL, GOMS_OPEN_REST_URL, HUAWEI_APAAS_DOMAIN_ADDRESS, ROMA_URLJava backend onlyDetermined by the network environment where the backend resides, not by frontend variables

1.3 Virtual Prefix Mapping

Both frontends perform prefix replacement in src/libs/request/server.ts. A request must first hit a Next route, and then serverRequest replaces the prefix.

PC (hoox-cms-pub-ui)

Virtual prefixTarget environment variableNotes
/api/cms-restCMS_REST_API_BASEPATHCMS client REST, usually the CMS RPC REST port
/api/cms-serverCMS_SERVER_API_BASEPATHCMS Web port (files/some MVC endpoints)
/api/message-restCMS_SERVER_API_BASEPATHMessage-related; also lands on the CMS Web port
/api/smp-restSMP_REST_API_BASEPATHDirect connection to SMP/Event Center
/api/cap-restCAP_REST_API_BASEPATHCAP RPC REST port
/api/cap-serverCAP_SERVER_API_BASEPATHCAP Web port; there is no corresponding physical Next route; called only internally by the server
/api/goms-restGOMS_REST_API_BASEPATHGOMS open APIs
/api/form-restPROXY_CLOUD_FORM_HOSTCloud Form; note that the UI uses the variable without NEXT_PUBLIC_

H5 (hoox-cms-pub-app)

Virtual prefixTarget environment variableNotes
/api-h5/cms-restCMS_REST_API_BASEPATHCMS client REST
/api-h5/cms-serverCMS_SERVER_API_BASEPATHCMS Web
/api-h5/smp-restSMP_REST_API_BASEPATHSMP
/api-h5/cap-restCAP_REST_API_BASEPATHCAP RPC REST
/h5/api-h5/cap-serverCAP_SERVER_API_BASEPATHNote that the prefix includes /h5
/api-h5/goms-restGOMS_REST_API_BASEPATHGOMS
/api-h5/form-restNEXT_PUBLIC_PROXY_CLOUD_FORM_HOSTCloud Form; H5 uses the variable with NEXT_PUBLIC_

Two details:

  1. serverRequest only performs string replacement; it does not automatically add slashes and does not modify the query. The base path must not end with /, and business paths must start with /.
  2. PC’s /api/cap-server, /api/cms-server, and /api/message-rest are “logical prefixes”; the browser should not access them directly. The actual file upload entry is usually a dedicated route such as src/app/api/(common)/cap-file-upload/route.ts. The same applies to H5’s /h5/api-h5/cap-server; there is no physical route with the same name.
  3. The existence of a prefix mapping does not mean there is necessarily a corresponding physical BFF route. For example, H5’s serverRequest supports /api-h5/goms-rest, but there is currently no goms-rest directory under src/app/api-h5; confirm that a route exists before adding a call.

2. Local Startup

2.1 Prerequisites

ItemRequirementBasis
JDK21maven.compiler.release=21 in both backend POMs
MavenCan access the intranet Nexus and resolve the hoox-common BOM and SOFA dependenciesThe POM depends on internal com.linewell.gov.hoox components
Node.jsPC >=20.9.0; H5 is recommended to use the same versionengines in hoox-cms-pub-ui/package.json; the UI also has engine-strict=true
npmUse npm; PC’s preinstall enforces only-allow npm.npmrc, package.json
DatabaseGaussDB/PostgreSQL, CAP schema hoox_cap, CMS schema hoox_cmsBoth dev/application-datasource-gauss-devops.properties
MiddlewareRedis, ZooKeeper (SOFA registry center)REDIS_*, SOFA_RPC_REGISTRY_ADDRESS
External platformsSMP, UAM/IDaaS, GOMS, etc. reachable as neededdev/application-devops.properties

Internal npm private registry addresses are written in the .npmrc of the two repositories: @linewell:registry=.... If npm install reports 404, first confirm the private registry and network; do not suspect the code first.

2.2 Backend Startup

CAP

cd D:\project\portal\hoox-cap-backend

# Method 1: Run directly in the IDE
#   gov-hoox-cap-run/src/main/java/com/linewell/gov/hoox/cap/run/CapWebApplication.java
#
# Method 2: Run after packaging (-Pdev selects resources/dev)
mvn -pl gov-hoox-cap-run -am clean package -Pdev -DskipTests
java -jar gov-hoox-cap-run\target\gov-hoox-cap-run-1.0-SNAPSHOT-executable.jar

After startup:

  • Web/MVC: http://127.0.0.1:8087
  • SOFA RPC REST: http://127.0.0.1:8346
  • Bolt: 22006

CMS

cd D:\project\portal\hoox-cms-backend

# Method 1: Run directly in the IDE
#   hoox-cms-run/src/main/java/com/linewell/gov/hoox/cms/run/CmsWebApplication.java
#
# Method 2: Run after packaging
mvn -pl hoox-cms-run -am clean package -Pdev -DskipTests
java -jar hoox-cms-run\target\hoox-cms-run-3.9.0-SNAPSHOT-executable.jar

After startup:

  • Web/MVC: http://127.0.0.1:8083
  • SOFA RPC REST: http://127.0.0.1:8343
  • Bolt: 22123

Maven profile vs. Spring profile: -Pdev is a Maven resource selection switch; on the Spring side, what is actually activated are fragments such as devops and datasource in spring.profiles.include. Do not write --spring.profiles.active=dev and then expect it to load resources/dev; that is not how this project works.

If the IDE reports “configuration not found” at runtime, first check whether the dev profile is activated in the Maven panel and whether application-devops.properties exists under target/classes.

2.3 Frontend Startup

cd D:\project\portal\hoox-cms-pub-ui
npm install
npm run dev
# http://localhost:8080

cd D:\project\portal\hoox-cms-pub-app
npm install
npm run dev
# http://localhost:8081/h5

Both dev scripts first run lingui:compile; therefore src/locales/** must be in a compilable state. If the copy was just changed, run npm run lingui:extract first.

2.4 Frontend Production Startup (Local Acceptance)

# PC
npm run build
npm run start        # next start -p 8000

# H5
npm run build
npm run start        # next start -p 8100

PM2 configuration is specified separately:

  • PC ecosystem.config.js: next start -p 8300
  • H5 ecosystem.config.js: next start -p 8100

npm run build executes lingui:extract --clean and lingui:compile, and both frontends run npm install once more during build. The build machine must be able to access the private registry, and after building you must check whether the locale files have unexpected changes.

3. Port and Address Matrix

3.1 Service Ports

ServiceLocal devNotes
CAP Web8087SERVER_PORT; Spring MVC/file Controller
CAP RPC REST8346RPC_REST_PORT; ordinary JAX-RS facade
CAP Bolt22006RPC_BOLT_PORT; SOFA Bolt
CMS Web8083SERVER_PORT
CMS RPC REST8343RPC_REST_PORT
CMS Bolt22123RPC_BOLT_PORT
PC dev8080next dev -p 8080
PC next start8000npm run start
PC PM28300ecosystem.config.js
H5 dev8081next dev -p 8081, access with /h5
H5 next start8100npm run start
H5 PM28100ecosystem.config.js

3.2 There Is a “Mismatch” in CAP’s Own Address Variables

In common/application-service-cap.properties:

cap.rest.address=${CAP_REST_ADDRESS:http://127.0.0.1:8341}
cap.web.address=${CAP_WEB_ADDRESS:http://127.0.0.1:8080}

However, the actual local dev listeners are REST 8346 and Web 8087. This indicates that these two variables are used by business code to assemble external/callback addresses, and are not necessarily equal to the actual SOFA bind ports. During integration:

  • The frontend accesses CAP with CAP_REST_API_BASEPATH=http://127.0.0.1:8346 and CAP_SERVER_API_BASEPATH=http://127.0.0.1:8087.
  • If a business-returned link/callback still points to 8341/8080, override it through the environment variables CAP_REST_ADDRESS and CAP_WEB_ADDRESS; do not modify the POM.

3.3 Frontend Addresses Registered in the Repository

In the two frontends’ .env.development and .env.production, the following values are basically identical (all are shared environment addresses):

VariableValue registered in the repository
CMS_REST_API_BASEPATHhttp://10.201.50.41:8345
CMS_SERVER_API_BASEPATHhttp://10.201.50.41:8083
SMP_REST_API_BASEPATHhttp://10.201.50.41:8344
CAP_REST_API_BASEPATHhttp://10.201.50.41:8342
CAP_SERVER_API_BASEPATHhttp://10.201.50.41:8081
GOMS_REST_API_BASEPATHhttp://10.201.50.41:8343

These values do not correspond one-to-one to the local backend ports:

  • The frontend CMS REST specifies 8345, while local CMS RPC REST is 8343.
  • The frontend CAP REST specifies 8342, while local CAP RPC REST is 8346.
  • The frontend CAP Web specifies 8081, while local CAP Web is 8087.

Therefore, local integration must explicitly override them; do not “see that 8083 matches and assume CMS is fully connected”. CMS Web’s 8083 happens to be the same, but REST is different.

3.4 Browser Access Addresses

Variabledevproduction
PC NEXTAUTH_URLhttp://localhost:8080http://192.168.203.33:3006
PC NEXT_PUBLIC_H5_SERVICE_ADDRESShttp://localhost:8081http://192.168.203.33:3006
H5 NEXT_PUBLIC_WEB_SERVICE_ADDRESShttp://localhost:8080http://192.168.203.33:3006
H5 NEXT_PUBLIC_APP_H5_URLhttp://manage-yf.linewell.com:6443/algeriaSame as left
For both, APP_API (H5)http://manage-yf.linewell.com:6443Same as left

NEXTAUTH_URL must be consistent with the address through which the browser actually accesses PC; otherwise the OAuth callback will be assembled incorrectly, and the typical error is a redirect_uri mismatch.

4. Frontend Configuration File Standards

4.1 File Responsibilities

FileWhen loadedCommittedPurpose
.env.developmentnext devYesLocal/development defaults
.env.productionnext build / next start (production mode)YesProduction/shared environment defaults
.env.localCorresponding mode, with higher priorityNoPersonal local overrides; currently absent from the repository
next.config.jsBuild/startupYesbasePath, compilation switches, images, externals; not the place for business addresses
ecosystem.config.jsPM2 startupYesProcess name, port, instance count, environment variable passthrough

Priority and override rules follow Next.js; the team convention is: shared defaults go into .env.development/.env.production, personal differences go into .env.local, and secrets do not go into Git.

4.2 Key Variable Groups

Backend Addresses (Used Server-Side, Without NEXT_PUBLIC_)

VariablePCH5Meaning
CMS_REST_API_BASEPATHRequiredRequiredCMS client REST
CMS_SERVER_API_BASEPATHRequiredConfigured*CMS Web/files
SMP_REST_API_BASEPATHRequiredConfigured*SMP
CAP_REST_API_BASEPATHRequiredRequiredCAP REST
CAP_SERVER_API_BASEPATHRequiredConfigured*CAP Web/files (logical prefix)
GOMS_REST_API_BASEPATHRequiredConfigured*GOMS
PROXY_CLOUD_FORM_HOSTRequired—PC Cloud Form proxy
NEXT_PUBLIC_PROXY_CLOUD_FORM_HOST—RequiredH5 Cloud Form proxy
APP_API—RequiredH5 third-party user/token service

* means that H5’s .env and serverRequest have this prefix, but there is currently no corresponding generic BFF route under src/app/api-h5; you cannot assume an API is callable merely because the variable exists. H5’s cms-server, smp-rest, goms-rest, and cap-server all fall into this case.

The reason these variables do not have the NEXT_PUBLIC_ prefix is that they are used only in Route Handlers/Server Components. Adding the prefix would put them into the client bundle and leak internal addresses.

Authentication and Login

VariablePCH5Notes
CLIENT_IDhoox-cms-pub-uihoox-cms-pub-appMust align with the backend’s hooxAppAuthProvider.<clientId>
CMS_API_AUTH_KRequiredRequiredCMS API RSA private key (ciphertext)
CAP_API_AUTH_KRequiredRequiredCAP API RSA private key (ciphertext)
SMP_API_AUTH_KRequiredCurrently absentPrivate key for PC to access SMP; if H5 adds signed calls, it must be added
GOMS_API_AUTH_KRequiredCurrently absentPrivate key for PC to access GOMS
FORM_API_AUTH_KRequiredRequiredCloud Form API private key
FORM_REST_API_AKRequiredRequiredCloud Form app_key (ciphertext)
NEXTAUTH_SECRETRequired—NextAuth JWT encryption
NEXTAUTH_URLRequired—OAuth callback base address
OAUTH_APP_BASEPATH / OAUTH_APP_IDRequiredRequiredOAuth service address/application ID
OAUTH_APP_SRequired—PC OAuth secret
OAUTH_APP_SECRET—RequiredH5 OAuth secret (name differs from PC)
OAUTH_APP_ROMA_*OptionalOptionalUsed when going through ROMA/OneAccess user information
APP_API_TOKEN_CHECK—Needs attentionValidates third-token when true

In code, *_API_AUTH_K is first passed through configDecrypt and then assembled into a PEM private key; it is not “just any signing salt”. When changing environments, the private key, backend public key, and CLIENT_ID must be changed together.

Runtime Switches

VariableCurrent stateNotes
NEXT_PUBLIC_SECURITY_GLOBAL_CLOSEtrue for both frontendsMaster switch for security handling in the client request library; does not mean the backend does not verify signatures
NODE_TLS_REJECT_UNAUTHORIZED0 for both frontends in dev/prodDisables Node TLS certificate verification; usable in self-signed environments, but production should be evaluated
NEXT_PUBLIC_HWBP_OPENPer environmentWhether to load the tracking SDK
NEXT_PUBLIC_OAUTH_ACCESS_TOKEN_VERIFY_INTERVAL_MSConfigured for PCAccess token verification time window; 0 means verify every time, <0 means skip
HOOX_AUTH_EXPIRE_TIMEConfigured for PCAuthentication header validity period (milliseconds)
NEXT_PUBLIC_KEEP_LOGIN / password/browser version variablesPer environmentLogin page and frontend validation policies

NEXT_PUBLIC_ Rules

  • NEXT_PUBLIC_* is inlined into the browser bundle at build time; if changed, it must be rebuilt.
  • Do not add NEXT_PUBLIC_ to actual server-side secrets. The current repository contains some historical variables with this prefix (such as NEXT_PUBLIC_SIGNATURE_PRIVATE_KEY and NEXT_PUBLIC_API_FORM_ENCRYPTION_AES_KEY); do not blindly imitate them when adding variables, first confirm whether it should originally be exposed to the browser.
  • Only browser-visible addresses (H5/APP redirects, OAuth callbacks) should use NEXT_PUBLIC_ or NEXTAUTH_URL.

4.3 Mandatory Differences Between PC and H5

ItemPCH5
BFF prefix/api/.../api-h5/...
Route basePathNone/h5
LoginNextAuth + OAuthCST SDK / token / encryt_uf
OAuth secret variableOAUTH_APP_SOAUTH_APP_SECRET
Cloud Form variablePROXY_CLOUD_FORM_HOSTNEXT_PUBLIC_PROXY_CLOUD_FORM_HOST
Third-party token validationNo such switchAPP_API_TOKEN_CHECK
Mobile redirectmiddleware.ts redirects to H5 by UANone
Component libraryantd 4antd 5 + antd-mobile 5

5. Backend Configuration File Standards

5.1 Key CAP Files

FileRoleCommonly changed during integration
gov-hoox-cap-run/src/main/resources/common/application.propertiesApplication name, dbType, spring.profiles.includeUsually unchanged
common/application-base.propertiesBasic items such as ports, i18n, encryption, and sessionsChange when ports/keys are involved
common/application-service-cap.propertiescap.rest.address, cap.web.address, upload limits, feature switchesChange when callback addresses are wrong
common/application-service-oauth.propertieshoox.oauth.auth.*, public keys for each clientId, authentication URL scopeMust check when switching frontend/keys
common/application-api-address.propertiesExternal addresses for archiving, SMP, EAC, payment, logging, etc.Change when switching external environments
common/application-plugins-gateway.propertiesHuawei gateway switch, ROMA address/typeChange when going through ROMA
common/application-service-huawei-apaas.propertiesaPaaS client/domain/userChange when integrating with aPaaS
common/application-data-redis.propertiesRedis connectionChange for local Redis
common/application-datasource.propertiesDruid data source defaultsUsually overridden by environment variables
common/application-datasource-mybatis.propertiesMapper paths, field encryption keyCheck when adding a Mapper/changing the key
dev/application-devops.propertiesPorts for this environment, SMP/EAC/payment/logging, ZK, Redis, UAMMain file for local integration changes
dev/application-other-devops.propertiesROMA, aPaaS, gateway switchChange when integrating with the Huawei environment
dev/application-datasource-gauss-devops.propertiesGaussDB address, schema, accountMain file for local database changes

The most frequently changed CAP keys locally:

SERVER_PORT=8087
RPC_REST_PORT=8346
RPC_BOLT_PORT=22006

DATABASE_IP=127.0.0.1
DATABASE_PORT=8000
SPRING_DATASOURCE_CAP_DRUID_URL=jdbc:postgresql://${DATABASE_IP}:${DATABASE_PORT}/db_nw?currentSchema=hoox_cap

SOFA_RPC_REGISTRY_ADDRESS=zookeeper://127.0.0.1:2181
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_DATABASE=4

SMP_OPEN_REST_URL=http://<smp-host>:<smp-port>
CAP_REST_ADDRESS=http://127.0.0.1:8346
CAP_WEB_ADDRESS=http://127.0.0.1:8087

The above is an illustration of “change to local machine/change to a reachable environment” and does not represent the repository’s existing values. External platforms such as SMP and payment usually do not have local instances, so enter the actually reachable addresses; passwords/keys must use the ciphertext for the current environment and must not be written in plaintext.

5.2 Key CMS Files

FileRoleCommonly changed during integration
hoox-cms-run/src/main/resources/common/application.propertiesApplication name, dbType, include listUsually unchanged
common/application-base.propertiesPorts, i18n, encryption, sessionsCheck when changing ports/language table sharding
common/application-data-mybatis.propertiesMapper paths, MyBatis-Plus schema, field encryptionCheck when adding a Mapper/schema
common/application-data-redis.propertiesRedis namespace/connectionChange for local Redis
common/application-data-oauth.propertiesAuthentication switch, clientId public key, authentication URLMust check when switching frontend/keys
common/application-data-depend.propertiesSMP/GOMS dependency API pathsChange when external APIs change
common/application-data-idaas.propertiesIDaaS role/permission checksCheck on 403 after login
common/application-datasource.propertiesData source defaultsUsually overridden by environment variables
dev/application-devops.propertiesPorts, SMP/GOMS, UAM, ZK, Redis, KMSMain file for local integration changes
dev/application-datasource-gauss-devops.propertiesGaussDB address, schema, accountMain file for local database changes

The most frequently changed CMS keys locally:

SERVER_PORT=8083
RPC_REST_PORT=8343
RPC_BOLT_PORT=22123

SPRING_DATASOURCE_CMS_DRUID_URL=jdbc:postgresql://127.0.0.1:8000/db_nw?currentSchema=hoox_cms
SOFA_RPC_REGISTRY_ADDRESS=zookeeper://127.0.0.1:2181
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_DATABASE=0

SMP_OPEN_REST_URL=http://<smp-host>:<smp-port>
GOMS_OPEN_REST_URL=http://<goms-host>:<goms-port>
PORTAL_DOMAIN_ADDRESS=http://localhost:8080

CMS has another point that must be checked at the same time:

# JDBC URL
currentSchema=hoox_cms

# MyBatis-Plus global schema
mybatis-plus.global-config.db-config.schema=dpmp

The two default values are inconsistent. When adding handwritten SQL / Mapper, if the table name does not include a schema, which schema the query actually lands on depends on the connection and framework configuration; confirm this during integration, and do not wait until production to discover that the wrong database was queried.

5.3 Configuration Layering Standards

LayerWhat to putWhat not to put
commonDefault values consistent across all environments, feature switch defaults, API path templatesIPs of a specific machine, accounts/passwords of a specific environment
dev/test/prodAddresses, ports, accounts, certificate paths unique to that environmentBusiness constants unrelated to the environment
Environment variables/startup parametersPasswords, IPs, switches injected at deployment timeDefault values that need version control
Database/configuration centerBusiness configuration that can change at runtimePorts/data sources required for startup

Conventions:

  1. New configuration items must have a default value or explicit required validation; do not leave implicit dependencies that “only production configures”.
  2. Address-type configuration must uniformly use a complete URL (including scheme, port, and context path); do not manually concatenate http:// in code.
  3. Passwords, private keys, and AK/SK must use the [ciphertext] form, and the decryption key for the current environment must be confirmed; plaintext commits are prohibited.
  4. Keep only one key for the same meaning. CAP already has CAP_REST_ADDRESS/CAP_WEB_ADDRESS; do not create another cap.url.
  5. When changing a port, check all of the following at the same time: this file, frontend base path, Nginx/gateway, OAuth callback, and SOFA registry address.
  6. When adding a fragment to spring.profiles.include, ensure that the corresponding application-<name>.properties exists on the classpath; otherwise startup will not report a “missing file”, but the related configuration will be silently missing.

6. Authentication Integration

6.1 Generation and Verification of HOOX-AUTH

The rsaEncrypt logic is identical in both frontends:

  1. Assemble the payload: clientId + user fields (when a login state exists) + extend.time, etc.
  2. Convert to Base64 after JSON.stringify.
  3. Use the RSA private key decrypted from *_API_AUTH_K to sign the Base64 string with RSA-SHA256.
  4. Assemble Base64(payload)-Base64(signature) and put it into HOOX-AUTH.
  5. The backend finds the hoox.oauth.auth.hooxAppAuthProvider.<clientId>.publicKey based on the clientId in the payload to verify the signature, and checks the validity period/URL scope.

The four items that must match in pairs:

FrontendBackend
CLIENT_IDhoox.oauth.auth.hooxAppAuthProvider.<clientId>
CMS_API_AUTH_K / CAP_API_AUTH_K / …The corresponding provider’s publicKey
Actual request pathauthIncludeUrl / authExcludeUrl regex
HOOX_AUTH_EXPIRE_TIMEBackend authentication validity period/clock

Backend signature verification switch:

hoox.oauth.auth.enable=${HOOX_OAUTH_AUTH_ENABLE:true}

Local temporary disable (local machine only, troubleshooting only):

$env:HOOX_OAUTH_AUTH_ENABLE="false"

After disabling, the BFF still sends HOOX-AUTH; the backend simply does not verify it. Do not commit the disabled state to the dev configuration, let alone carry it into test/prod.

6.2 PC Login and CSRF

sequenceDiagram
  autonumber
  participant U as User browser
  participant UI as PC Next.js
  participant IDP as IDaaS/OneAccess
  participant BFF as PC BFF
  participant API as CMS/CAP

  U->>UI: Click login
  UI->>UI: signIn('cms')
  UI->>IDP: OAuth authorize
  IDP-->>UI: /api/auth/callback/cms?code=...
  UI->>IDP: Exchange token / getUserInfo
  UI->>UI: Establish NextAuth JWT session
  U->>BFF: /api/... + session cookie + x-csrf-token
  BFF->>BFF: withAuth validates session/CSRF/access token
  BFF->>API: HOOX-AUTH + language/user headers

Integration points:

  • NEXTAUTH_URL must be consistent with the browser address; http://localhost:8080/api/auth/callback/cms must be registered in the OAuth application.
  • The CSRF Cookie name is __Host-next-auth.csrf-token under HTTPS and next-auth.csrf-token under HTTP; withAuth compares the Cookie with the x-csrf-token header (POST must include it).
  • getSignature skips only CSRF, not session/access token; single-scene-guide-get skips the entire authentication block in the CAP proxy.
  • The one-access-token header can bypass session/CSRF but still verifies the access token; this is for specific integration scenarios and should not be treated as a normal login method.
  • Logout first clears the Cloud Form cache and revokes the access token, and only then verifies CSRF; do not break this order when changing the logout logic.

6.3 H5 Login and Token

sequenceDiagram
  autonumber
  participant App as InnoApp/WebView
  participant H5 as H5 Next.js
  participant BFF as H5 BFF
  participant APP as APP_API
  participant API as CAP/CMS

  App->>H5: Open /h5/... ?token=...
  H5->>H5: Write token Cookie / read CST token
  H5->>BFF: /h5/api-h5/... + token + base-params
  alt APP_API_TOKEN_CHECK=true
    BFF->>APP: verify-third-token
    APP-->>BFF: status=1
  end
  BFF->>API: HOOX-AUTH + token + base-params

Integration points:

  • APP_API_TOKEN_CHECK: default false in dev and true in prod. When local login fails, confirm this first; do not start by changing the backend.
  • encryt_uf is a server-side encrypted user information Cookie written by the app-user-info route; do not forge it manually, and check its decryption result when troubleshooting.
  • base-params includes at least appId and lang; the H5 request library automatically supplements defaults such as {"appId": A_ID, "lang": "en_US"}.
  • H5’s rsaEncryptSign only handles the three prefixes /api-h5/cap-, /api-h5/form-, and /api-h5/cms-; when adding SMP/GOMS signed calls, the branch must be extended accordingly, otherwise HOOX-AUTH may not be obtained.
  • H5 has no NextAuth and no CSRF double submit; do not copy PC’s login troubleshooting steps.

7. Integration Scenarios

Scenario A: Change Only the Frontend and Connect to the Shared Environment

Applicable: page/style/interaction development, with the backend on the shared environment.

  1. Keep the 10.201.50.41 addresses in .env.development unchanged.
  2. npm install && npm run dev.
  3. PC login requires a shared environment IDaaS account; H5 requires an InnoApp container or a valid token.
  4. Do not modify CLIENT_ID/*_API_AUTH_K, otherwise the shared environment backend will not recognize them.

Scenario B: PC + Local CMS

Applicable: changing CMS client APIs and PC content display.

  1. Start CMS (8083/8343) and ensure DB/Redis/ZK are reachable.
  2. Modify hoox-cms-pub-ui/.env.development:
CMS_REST_API_BASEPATH=http://127.0.0.1:8343
CMS_SERVER_API_BASEPATH=http://127.0.0.1:8083
NEXTAUTH_URL=http://localhost:8080
  1. CAP/SMP/GOMS can continue pointing to the shared environment; if the page only uses CMS, there is no impact.
  2. Confirm on the IDaaS side that http://localhost:8080/api/auth/callback/cms is registered.
  3. Start PC, and confirm in the browser Network panel that /api/cms-rest/... returns 200 and that the CMS logs contain the corresponding request.

Scenario C: H5 + Local CAP

Applicable: changing the declaration flow, materials, payment, and H5 BFF.

  1. Start CAP (8087/8346).
  2. Modify hoox-cms-pub-app/.env.development:
CAP_REST_API_BASEPATH=http://127.0.0.1:8346
CAP_SERVER_API_BASEPATH=http://127.0.0.1:8087
CMS_REST_API_BASEPATH=http://127.0.0.1:8343
APP_API_TOKEN_CHECK=false
  1. If APP_API is unreachable, APP_API_TOKEN_CHECK=false in dev can bypass validation first; however, app-user-info may still need APP_API, so login state issues must be examined separately.
  2. Change the Cloud Form address to a reachable environment; otherwise the form-filling step will show a blank screen/time out.
  3. Open http://localhost:8081/h5/... using InnoApp or a URL with ?token=.

Scenario D: All Four Projects Local

  1. Start CMS and CAP first, then start PC and H5.
  2. Point the two frontends to the local backend respectively; H5’s CMS_REST_API_BASEPATH must also point to the local CMS (if H5 pages use CMS content).
  3. Change CMS’s PORTAL_DOMAIN_ADDRESS to http://localhost:8080 to prevent backend-generated links from jumping back to the shared environment.
  4. If CAP returns file/payment callback addresses, set CAP_REST_ADDRESS and CAP_WEB_ADDRESS as needed.
  5. IDaaS/APP_API/Cloud Form generally cannot be localized and still need to connect to the shared environment; this is “semi-local” integration, not fully offline.

Scenario E: Verify Backend APIs Only

Prefer Swagger or unit tests; do not manually assemble HOOX-AUTH. If a direct connection is necessary:

  • Temporarily set HOOX_OAUTH_AUTH_ENABLE=false (local machine only).
  • Use Test-NetConnection 127.0.0.1 -Port 8343 to confirm the port.
  • When connecting directly, supply headers such as Content-Language, token, and base-params yourself; this cannot replace BFF integration.

8. Complete Steps for Adding a Frontend-Backend API

Take “adding a CAP query API on PC” as an example:

  1. Backend: define the JAX-RS method in *-facade, implement it in *FacadeImpl, and confirm the complete path (including /hoox/cap/...) and HTTP method.
  2. BFF data source: add a method under src/core/datasources/{client,server}/...; the path must start with /api/cap-rest/....
  3. BFF whitelist: add the exact path (without query) to WHITELIST_GET_PATHS or WHITELIST_POST_PATHS in src/app/api/cap-rest/[[...proxy]]/route.ts.
  4. Authentication: confirm whether a withAuth exclusion is needed; by default, do not exclude. When CSRF must be skipped, add only csrfExcludes; do not also skip session in passing.
  5. Response: consume according to BaseResponse; for file streams/encrypted responses, refer to the existing hoox-data-secret branch and do not use Response.json directly.
  6. H5 (if needed): repeat steps 2-4, but change the prefix to /api-h5/..., and check whether H5’s rsaEncryptSign covers that prefix.
  7. Tests: add datasource/route unit tests; cover at least whitelist hit, miss 404, authentication failure, and normal response.

BFF Route Template

When a dynamic proxy ([[...proxy]]) already exists, usually only the whitelist needs to be added; when there is no dynamic proxy, create:

// src/app/api/xxx/route.ts
import type { NextRequest } from 'next/server';

import { serverRequest } from '@/libs/request/server';
import { addAuthHeader, withAuth } from '@/utils/server/authCheck';

export const GET = withAuth(
  addAuthHeader(async (request: NextRequest) => {
    const data = await serverRequest('/api/cms-rest/hoox/cms/client/...', {
      method: 'GET',
      headers: request.headers,
      request,
    });
    return Response.json(data);
  }),
);

Notes:

  • The request option of serverRequest is used to pass through the client IP; not all routes must pass it, but it should be passed when risk control/auditing is involved.
  • Return a Response rather than a plain object; file streams must retain Content-Type/Content-Disposition.
  • Dynamic proxy path matching uses exact strings, and the query is removed by split('?')[0]; do not include a query in new paths.
  • Use kebab-case for route directory names; use - for business segments, such as cap-rest and cms-server; do not use underscores or camelCase.

9. Common Troubleshooting

SymptomCheck firstAction
BFF returns 404 Not FoundRequest method, virtual prefix, exact whitelist pathAdd the path to WHITELIST_* in the corresponding route.ts; confirm GET/POST is not reversed
BFF returns ESYS120001NextAuth session, CSRF, access token, encryt_ufLog in to PC again; check x-csrf-token; for H5 check APP_API_TOKEN_CHECK and the token
Backend returns signature verification failure/401CLIENT_ID, private/public key, request path, clockConfirm that the frontend *_API_AUTH_K and backend publicKey are paired; confirm that authIncludeUrl covers the path
fetch failed / 502Base path port, whether the backend is started, TLSTest-NetConnection; confirm whether the BFF uses the RPC REST or Web port
OAuth reports redirect_uriNEXTAUTH_URL, IDaaS registrationChange to the actual browser address; the callback path is /api/auth/callback/cms
H5 page 404Whether /h5 is includedAccess http://localhost:8081/h5/...; if the BFF also requires /h5, follow the actual route
Response fields missingWhether this is H5 POST normalization; whether hoox-data-secret is involvedH5 POST retains only 5 fields; when complete fields are needed, change the proxy or use GET/a dedicated route
Still redirected to unauthorized after loginH5 shouldAllowBusinessAccess, token/taowl, user typeCheck the decision in layout.tsx and the encryt_uf decryption result; confirm it is not a public preview page
Local page connects to the shared environmentWhether .env.local/.env.development is overridden, whether it was rebuiltRebuild after changing NEXT_PUBLIC_*; restart Node after changing server-side variables
File upload 404/413Whether it goes through Web or RPC REST, upload size limitsFile operations go through *_SERVER_API_BASEPATH; check the upload limits in application-service-cap.properties
Occasional API 429Client rate limiting, gateway rate limitingCheck the 429 handling in src/libs/request/client.ts; do not bypass it by repeated clicking

10. Configuration Change Checklist

Confirm each item before committing:

  • Are new variables added to both .env.development and .env.production (or explicitly scoped to only one environment)?
  • Was NEXT_PUBLIC_ mistakenly added to a server-side address?
  • Are CLIENT_ID, the private key, and the backend public key paired?
  • Is the new BFF path in the whitelist, and is the method correct?
  • After changing a port, were the frontend base path, OAuth callback, gateway, and SOFA registry updated accordingly?
  • After changing the schema, were both the JDBC URL and MyBatis-Plus schema checked?
  • Does new configuration have a default value/required validation?
  • Were real keys, intranet passwords, or personal tokens written into documentation or code?
  • Was the project rebuilt after changes to NEXT_PUBLIC_*?
  • Did local verification cover at least one case each of “no login/login expired/cross-language/file stream”?