Collabora (CODE) Integration
Use Collabora Online (CODE) to view and edit office files inside nextExplorer using the WOPI protocol.
Requirements
- A Collabora CODE server reachable by the user’s browser (e.g.
https://collabora.example.com). - nextExplorer must have a correct
PUBLIC_URL(Collabora calls back to your app using this). - Your reverse proxy in front of Collabora must support WebSockets (this is the most common cause of “socket connection closed unexpectedly” errors).
Environment variables (nextExplorer backend)
| Variable | Required? | Description |
|---|---|---|
COLLABORA_URL | Yes | Public base URL of Collabora (e.g. https://collabora.example.com). |
PUBLIC_URL | Yes | Public base URL of nextExplorer (e.g. https://files.example.com). Used to build the WOPI URLs Collabora calls. |
COLLABORA_SECRET | Yes | Shared JWT secret used to sign WOPI access_token values. |
COLLABORA_DISCOVERY_URL | No | Discovery endpoint override. Defaults to ${COLLABORA_URL}/hosting/discovery. |
COLLABORA_LANG | No (default en) | Language code for the Collabora UI. |
COLLABORA_FILE_EXTENSIONS | No | Comma-separated list of office extensions to enable (otherwise nextExplorer uses defaults or discovery). |
Collabora container example (TLS termination at reverse proxy)
Collabora’s domain setting is a regex that must match your nextExplorer host.
yaml
services:
collabora:
image: collabora/code:latest
restart: unless-stopped
cap_add: [MKNOD]
ports:
- '9980:9980'
environment:
- domain=files\\.example\\.com
- server_name=collabora.example.com
- username=admin
- password=change-me
- extra_params=--o:ssl.enable=false --o:ssl.termination=trueReverse proxy (Collabora)
If you see:
“Failed to establish socket connection or socket connection closed unexpectedly…”
your proxy is almost always missing Collabora’s WebSocket forwarding for:
^/cool/(.*)/ws$(main editing websocket)/cool/adminws(admin console websocket)
If you use Nginx Proxy Manager, turn on Websockets Support for the collabora.example.com proxy host. For raw Nginx examples, see Collabora’s proxy guide:
https://sdk.collaboraonline.com/docs/installation/Proxy_settings.html
How it works (high level)
- The UI calls
POST /api/collabora/configto obtain a CollaboraurlSrc(iframe URL) and a signedaccess_token. - The browser loads the Collabora iframe.
- Collabora calls nextExplorer’s WOPI endpoints (e.g.
GET /api/collabora/wopi/files/:fileId) using theaccess_tokento read/write and manage locks.
Troubleshooting
- Socket connection closed / websocket 400: enable WebSocket support on the reverse proxy in front of Collabora and ensure
/cool/(.*)/wsis proxied withUpgrade/Connectionheaders and long read timeouts. - Collabora says the WOPI host is not allowed: your Collabora
domainregex doesn’t matchPUBLIC_URL’s host. Invalid access_tokenin nextExplorer logs:COLLABORA_SECRETmismatch, multiple backend instances using different secrets, or the request URL/token is being modified/truncated by a proxy.
