Let the browser safely receive only the Nacos JSON configs you allow

Live recording: after publishing in Nacos, the page updates without a reload
Live recording: publish in the Nacos console, and the page updates over same-origin SSE. Click to enlarge.

Why you need it

Banners, feature flags, and campaign copy often live in Nacos.

Ops wants the live page to change as soon as they publish—not after the next frontend release.

But the page should not talk to Nacos itself.

So let your Spring Boot app talk to Nacos, and let the page talk only to your app. You list which names the page may see; the backend checks them and pushes updates.

ScenarioHomegrown / direct accessnacos-web-config
Where credentials liveEasy to put in the frontend; a stolen account can change or delete configsCredentials stay on the backend
How much you can openNacos authorizes by namespace; you cannot open just one configOnly the names you list
Exposure of NacosOpening it to the public risks taking the config center downThe page talks only to your backend
Ops publishes bad JSONRules are yours; the page often breaksDrop bad data; keep the last good value
Show updates soon after publishKeep polling, or build push yourselfBackend pushes changes
Nacos is briefly downYou invent the behaviorValues on the page are not cleared
Integration costCache, protocol, testsOne dependency, a few lines of YAML, one subscribe() call

How data flows

No extra process, database, or admin console. Install it on the Spring Boot app that serves browsers. Click nodes and zoom; open the full interactive page anytime.

Open the full architecture diagram

nacos-web-config:
  enabled: true          # off unless explicitly enabled
  access: public        # required: public | authenticated
  nacos:
    server-addr: 127.0.0.1:8848
  exposures:              # whitelist: logical key → fixed Nacos coordinates
    ui:
      group: WEB_DEMO
      data-id: web-demo.public.json
      max-bytes: 65536
  • YAML
  • Whitelist

Authorization lives in YAML

What may leave the server is decided by the whitelist: each logical key maps to fixed Nacos coordinates plus a byte cap. Login and auth stay with the host security chain. The starter does not invent its own.

Quick start

Add the starter and whitelist on the backend, subscribe on the frontend. Full options are in the GitHub README “Configuration reference”.

  1. Step 1

    Backend: add the starter and declare the whitelist

    <dependency>
      <groupId>io.github.fatmii.nacoswebconfig</groupId>
      <artifactId>nacos-web-config-spring-boot-starter</artifactId>
      <version>0.2.0</version>
    </dependency>
    nacos-web-config:
      enabled: true
      access: public
      nacos:
        server-addr: 127.0.0.1:8848
      exposures:
        ui:
          group: WEB_DEMO
          data-id: web-demo.public.json
          max-bytes: 65536

    This exposes the SSE endpoint at /_web-config/v1/stream; to change it, set path: /your-prefix under nacos-web-config: in application.yml, same level as enabled. Choose access: public (anyone who reaches the endpoint may read the whitelist) or authenticated (a stream opens only when the request already has a signed-in identity).

  2. Step 2

    Frontend: subscribe

    $ npm install @fatmii/nacos-web-config
    import { createWebConfig } from '@fatmii/nacos-web-config'
    
    const config = createWebConfig({
      endpoint: '/_web-config/v1/stream', // optional: the default; pass it only after changing the starter's path
      // decode is likewise optional; add one when you need stricter checks
      definitions: {
        ui: { fallback: { announcement: '' } },
      },
    })
    
    const unsubscribe = config.subscribe('ui', state => {
      renderAnnouncement(state.value?.announcement ?? '')
    })
    // config.get('ui') reads current state; the shared connection opens on the first subscribe()
  3. Step 3

    Local demo

    # Needs JDK 17, Maven, and Docker that can run linux/amd64
    $ cd dev-environment
    $ docker compose --project-name nacos-web-config-local up -d nacos2
    # wait until http://127.0.0.1:18848/nacos responds
    
    $ cd ..\java
    $ $env:NACOS_SERVER_ADDR='127.0.0.1:18848'
    $ mvn -pl examples/spring-mvc -am spring-boot:run

    Open http://127.0.0.1:8080/, publish web-demo.public.json under group WEB_DEMO in Nacos (e.g. {"announcement":"hello"}). The page should update within a few seconds. More detail: java/examples/spring-mvc/ and dev-environment/ in the repo.

Compatibility

DependencyVersionNotes
Java17+Spring Boot 3.x, servlet/MVC
Nacos client2.5.3single supported client line
Nacos server2.5.3full chain verified (Java IT + browser E2E; nightly CI)
Nacos server3.2.3Full chain verified (Java IT + browser E2E; nightly CI)
Browsersmodernfetch + ReadableStream; no EventSource fallback

FAQ

Does Nacos get exposed to the frontend?

No. The browser only talks to a same-origin SSE endpoint on your own backend and can only reach logical keys explicitly declared in the YAML whitelist. The Nacos address, credentials, group / dataId / namespace never pass through the browser.

Why can't the browser talk to Nacos directly?

A password in JS is visible to anyone, and a Nacos account can change configs. Nacos also cannot expose “only this one config” to a page. Opening it to the public risks taking the config center down. Let your backend talk to Nacos. The page talks only to your backend, and only gets the configs you allowed beforehand.

Why SSE instead of polling or WebSocket?

This is one-way config push. SSE is ordinary HTTP: same-origin, reuses your auth and gateways, cheap in the browser. The protocol carries monotonic sequence numbers and a stream ID; snapshots precede deltas; out-of-order events are rejected; reconnects refetch a snapshot. Polling cannot do that. WebSocket leaves you to build it.

Why not just expose one plain endpoint and poll it?

A homegrown polling API still leaves you to own auth, whitelist mapping, bad-data handling, push, and reconnect behavior. This project packages those: only named configs reach the page, bad data does not break the UI, and publishes push over SSE. Integration is a dependency, YAML, and subscribe().

How does authentication work?

access is public or authenticated, and must be set or startup fails. public: anyone who reaches the endpoint may read the whitelist (read-only). authenticated: a stream opens only when the request already has a principal. The starter checks getUserPrincipal(); it does not log anyone in. With no login wiring, every call is 401. The level is per stream, not per key.

What if ops publishes a broken config?

Content is hard-validated: it must be a JSON object within max-bytes. Non-conforming content is rejected and never overwrites the last known good value. If Nacos as a whole is unreachable, data is merely marked stale and pages keep rendering the last valid config.

What can I monitor in production?

A host that runs Spring Boot Actuator automatically gains a health component: whether Nacos is currently reachable, plus the state each key is serving (ready / invalid / deleted / unavailable). Three metrics appear as well: open stream count, frames written by frame kind, and refused publishes counted by reason code. A host without Actuator is untouched. Both switches are Spring Boot's own and both start closed: until you set management.endpoint.health.show-details: always, /actuator/health/nacosWebConfig answers 404 and the aggregate URL carries only UP/DOWN; until you set management.endpoints.web.exposure.include: health,metrics, all three metric URLs answer 404 — measured. The README's "Operations (optional)" section has the paste-ready snippets and the measured response for every URL.

Will Chinese content get mangled?

Not along the delivery path: the stream is UTF-8, the browser needs no charset setting, and we measured Chinese values arriving intact (Nacos 2.5.3). The risk is the publishing step: sending Chinese inline from a Windows command line was measured to store non-UTF-8 bytes in Nacos — and because the result is still syntactically valid JSON, the content check cannot reject it, so the page just shows garbage. Publish from a UTF-8 file instead (--data-urlencode "content@D:/absolute/path.json"; the Windows curl cannot read /tmp/... paths), and use a decode guard as a backstop (throw on a value containing the replacement character or an impossible length and the runtime keeps the last known good value). See "Chinese content, and Windows" in the README.

How do I wire it into a React or Vue app locally?

The SDK always asks the origin that served the page, so a dev server only has to forward /_web-config: in Vite, server.proxy: { '/_web-config': { target: 'http://127.0.0.1:8080' } } — nothing else. Measured with Vite 8.3.4 in front of the demo host, a config publish reached the browser in 73–158 ms, the same as talking to the backend directly, and Vite's default compression did not buffer the stream. Two Vite quirks: it listens on the IPv6 loopback only, so open http://localhost:5173 (127.0.0.1 answers nothing), and a production build proxies nothing — ship static files and the endpoint on one origin, or point endpoint elsewhere. The React and Vue snippets live in the README's "Front-end dev server and framework wiring" section; both were rendered in a real browser and pass vite build.

What does a gateway or reverse proxy need to get right?

Our measurements found exactly two things that bite. First, the gateway's idle read timeout (nginx proxy_read_timeout) must be longer than the heartbeat interval (15s by default), otherwise the stream is cut on every idle window — the SDK reconnects and keeps the previous value on screen, but the page goes stale periodically. Second, pass Host $http_host, not $host, or your host application's login redirects lose the port. Buffering is usually not your problem: the response already carries X-Accel-Buffering: no and Cache-Control: no-store, which nginx honours. Self-check: curl -N -H 'Accept: text/event-stream' https://your-host/_web-config/v1/stream?key=ui should print event:snapshot immediately. The README's "Behind a gateway or proxy" section lists every measured number, including which gateways we did not test.

What are the limitations?
  • Whitelist keys are fixed at startup; adding a key means editing config and restarting.
  • Servlet MVC only; no WebFlux.
  • Values must be JSON objects under max-bytes.
  • ESM-only SDK; older browsers need your own bundler/polyfill.
  • No admin UI; create and edit configs in the Nacos console.
Which third-party dependencies come along, and do they override my versions?

Only nacos-client (2.5.3) arrives with us. jackson, tomcat and Spring stay under your own BOM: a minimal test project that imported Spring Boot 3.5.16 used jackson-databind 2.21.4 and tomcat-embed-core 10.1.55, not the 2.21.7 / 10.1.60 our own build pins for security advisories — if you want those fixes, manage them in your dependencyManagement. Going the other way works the same: pinning jackson-bom to 2.19.0 in that same project produced 2.19.0, silently, with nothing from us overriding it. So check with mvn dependency:tree instead of assuming. The README's "Who decides which versions end up in your application" section has the full table.

Is there a full configuration reference?

Yes. The README “Configuration reference” is a full YAML sample with defaults and inline comments for every field. One principle: any invalid value fails startup with a precise message—nothing is silently defaulted.

Does exposing several configs mean several connections?

No. The whole whitelist of one backend instance shares a single connection: the browser puts every subscribed key on one request (32 keys per connection by default), the first snapshot carries all of them, and later each changed key is pushed individually. An instance serves exactly one namespace; spanning namespaces means another instance.

Adding a new exposed config — does that mean rebuilding and redeploying?

No business-code change: add one allowed entry in application.yml and restart. Add the same name under frontend definitions. Fields that change often can live in one JSON object, so ops edits go live without adding more public entries.

Does the frontend require a specific framework?

No framework lock-in. The SDK is a TypeScript library with a plain subscribe / get model—use it from React, Vue, or vanilla pages. It requires a modern browser with fetch + ReadableStream support.

More detail: GitHub README

Actively shipping
v0.2.0

An operational surface, and integration docs we measured

Optional Actuator health component and three metrics; a host without Actuator is unchanged.

Gateways, dev-server proxies, React and Vue wiring, and Chinese content — written from measurements.

Browser end-to-end runs in CI against real Nacos 2.5.3 and 3.2.3, including a host restart and an Nginx proxy.

Get it

0.2.0 is on Maven Central and npm. Add a dependency or run npm install.

npm Published

npm install @fatmii/nacos-web-config, version 0.2.0 — TypeScript ESM, no runtime dependencies.

View package

Build from source

With JDK 17+, Maven and Node.js: run mvn verify under java/, and npm ci && npm test && npm run build under browser/.

Build instructions

You can also build from GitHub source. Please do not file public issues for vulnerabilities — see SECURITY.md.