This blog post includes some tips and tricks how to use WOPI protocol in combination with OnlyOfice.
OnlyOffice is a powerful collaborative web based document editor. OnlyOffice supports most of the common office document formats for editing Spredsheets, Documents, or Presentations.
WOPI is a standard web protocol for integrating web based document editors into a Web application. It was initially developed by Microsoft and is adapted from different Web Editors like OnlyOffce, Collabora and of course Microsoft Office. OnlyOffice supports the WOPI standard since version 6.4. Information about using WOPI API with OnlyOffice can be found here.
Docker
You can run OnlyOffice as a Docker Container easily. The following example shows a possible setup for a Web Application (my-app) and a OnlyOffice Docker container:
version: "3.6"
services:
imixs-documents:
image: imixs/imixs-documents:latest
environment:
# ONlyOffice integration
WOPI_PUBLIC_ENDPOINT: "http://localhost:80/"
WOPI_DISCOVERY_ENDPOINT: "http://onlyoffice-app/hosting/discovery"
WOPI_HOST_ENDPOINT: "http://imixs-documents:8080/api/wopi/"
WOPI_OPTIONS: "thm=1"
ports:
- "8080:8080"
onlyoffice-app:
image: onlyoffice/documentserver
container_name: onlyoffice-app
environment:
TZ: "Europe/Berlin"
USE_UNAUTHORIZED_STORAGE: "true"
DOCUMENT_SERVER_PORT_80_TCP_ADDR: "onlyoffice-app"
expose:
- 80
ports:
- "80:80"
volumes:
- ./configuration/onlyoffice/local-production-linux.json:/etc/onlyoffice/documentserver/local-production-linux.json
Running OnlyOffice as a Docker Container does not really need much configuration, as the Docker image brings all components out of the box. The Document Server will be accessible via port 80.
The most interesting part is the volume mapping for the config file local-production-linux.json
. This JSON file can be used to provide custom configuration options.
All config details provided by this fill will overwrite the default.json configuraiton. You can check the defauls from inside the running container at the file path:
/etc/onlyoffice/documentserver/default.json
The most important configuration parameter to enable the WOPI protocol is ‘"wopi": {"enable": true}
‘.
Another interesting config option is the ‘CoAuthoring’ which allows you to configure the behaviour of saving a document, which is especially important if your WOPI Host depends on a full control over the save command. For our Imixs-WOPI-Adapter implementation we set this parameter to force a WOPI POST request each time the updates the document in OnlyOffice. A result of a custom configuration can look like this:
{
"services": {
"CoAuthoring": {
"autoAssembly": {
"enable": true,
"interval": "0m",
"step": "0m"
}
}
},
"wopi": {
"enable": true
}
}
In this example I enable the autoAssembly option of the CoAuthoring service and set the delay interval to 0. You can find more information about the so called forcesave option here.
The Debug Mode
During development it may be helpful to activate the debug mode in OnlyOffice. This can give you more insights what is happening when your Application is communicating with OnlyOffice via the WOPI Protocol or also the OnlyOffice API.
To enable the debug mode you can create a new log4js configuration file named “production.json” like this:
{
"appenders": {
"default": {
"type": "console",
"layout": {
"type": "pattern",
"pattern": "[%d] [%p] %c - %.10000m"
}
}
},
"categories": {
"default": {
"appenders": [
"default"
],
"level": "DEBUG"
}
}
}
The last param ‘level’ is set form ‘WARN’ to ‘DEBUG’.
Next you can map this file in your Docker-Compose configuration as a local volume
onlyoffice-app:
image: onlyoffice/documentserver
container_name: onlyoffice-app
environment:
TZ: "Europe/Berlin"
#WOPI_ENABLED: "true"
USE_UNAUTHORIZED_STORAGE: "true"
DOCUMENT_SERVER_PORT_80_TCP_ADDR: "onlyoffice-app"
expose:
- 80
ports:
- "80:80"
volumes:
- ./configuration/onlyoffice/local-production-linux.json:/etc/onlyoffice/documentserver/local-production-linux.json
# Enable debug
- ./configuration/onlyoffice/log4j/production.json:/etc/onlyoffice/documentserver/log4js/production.json
Now restart you containers. Now you will see all debug messages in the docker-compose output. Or you can check the logfiles from inside the OnlyOffice Docker container with the command:
$ tail -f /var/log/onlyoffice/documentserver/docservice/out.log