How to Configure the Spire.OfficeJS Editor Service

2026-11-07 05:02:41 Written by  liu talia
Rate this item
(0 votes)

After deploying Spire.OfficeJS, the editor service reads its runtime settings from default.json. In real deployments, port conflicts, autosave cadence, and database connections often need to be adjusted to match the environment. This article explains how to change these common settings and how to make the changes take effect.

Editor Service Overview

OfficeServer is the Spire.OfficeJS editor service. It listens on port 8000 by default and handles resource distribution, runtime APIs, co-editing, caching, and license configuration. Co-editing, autosave, and document change synchronization all depend on it.

The deployment package provides startup scripts for different systems. Run them from the deployment package root:

  • Windows: double-click run_servers_window.bat.
  • Linux x64: run ./run_servers_linux_x64.sh start.
  • Linux ARM64: run ./run_servers_linux_arm64.sh start.

The scripts start both the example service and the editor service. The example service is for demonstration only and uses port 3000 by default. Once the editor service starts, port 8000 is listening.

Configuration File and Editor Invocation

All editor service settings are stored in default.json. The file is located in the platform-specific directory of the deployment package:

  • Windows: service/OfficeServer/window/config/default.json
  • Linux x64: service/OfficeServer/linux-x64/config/default.json
  • Linux ARM64: service/OfficeServer/linux-arm64/config/default.json

Before changing the configuration:

  • Back up default.json first.
  • The file must be strict JSON: comments are not supported, and trailing commas are not allowed.
  • Restart the service for the changes to take effect.

To invoke the editor service from a page, load SpireCloudEditor.js, then set coAuthorUrl in config.editorAttrs.serverless to the editor service address. Use http://LocalExample:8000 and replace LocalExample with the actual deployment address. Then call new SpireCloudEditor.OpenApi('editor', config).

Example configuration:

var config = {
  fileAttrs: {
    fileInfo: 
    { name: 'sample.docx', 
      ext: 'docx', 
      primary: '001' 
    },
    sourceUrl: 'http://LocalExample:3000/samples/sample.docx'
  },
  user: 
  { id: 'uid-1', 
    name: 'Jonn', 
    canSave: true 
  },
  editorAttrs: {
    editorMode: 'edit',
    editorType: 'document',
    viewLanguage: 'en',
    useWebAssemblyDoc: true,
    canForcesave: true,
    serverless: {
      useServerless: true,
      baseUrl: 'http://LocalExample:3000',
      coAuthorUrl: 'http://LocalExample:8000' // OfficeServer address
    },
  }
};

new SpireCloudEditor.OpenApi('editor', config);

The effect after accessing port 8000 is shown below:

Port 8000 effect

Common Settings

For most deployments, the three settings adjusted most often are the port, autosave interval, and database connection. They are described below.

Change the Editor Service Port

OfficeServer, as the editor service, listens on port 8000 by default. Pages use this port to access co-editing and other APIs. If the port is occupied or needs to be isolated from existing services, change it. After the change, update coAuthorUrl on pages that connect to the editor service; otherwise, the page cannot reach the editor service.

Example configuration (default port changed to 9000):

{
  "ServicesInformation": {
    "OfficeServer": {
      "server": {
        "port": 9000
      }
    }
  }
}

Restart the service. Once port 9000 is listening, the configuration has taken effect.

Set the Autosave Interval

In fast co-editing mode, the editor submits changes to the shared document session at a fixed interval. The interval is controlled by expire.autosave_interval and is measured in milliseconds.

Parameter Type Default Description
ServicesInformation.OfficeServer.expire.autosave_interval integer 600000 Autosave interval (ms). Default: 10 minutes.

Common conversions:

Interval Value
1 second 1000
1 minute 60000
5 minutes 300000
10 minutes 600000
15 minutes 900000

For example, to change the interval to 5 seconds:

{
  "ServicesInformation": {
    "OfficeServer": {
      "expire": {
        "autosave_interval": 5000
      }
    }
  }
}

Note

autosave_interval cannot be less than 0. A value below 0 is invalid, and the server uses the default value instead.

Configure the Database Connection

OfficeServer uses SQLite by default, storing task results and document changes in local files. This is suitable for single-server and small-scale deployments. For centralized data management, data sharing across instances, or higher concurrency, switch to an external database such as MySQL.

To switch, remove the existing sqlite3 object under OfficeServer and configure the sql object with the actual connection details.

Parameter Type Default Description
OfficeServer.sql.type string "mysql" Database type.
OfficeServer.sql.dbHost string "127.0.0.1" Database host address.
OfficeServer.sql.dbPort integer 3306 Database port.
OfficeServer.sql.dbUser string "root" Database user name.
OfficeServer.sql.dbPass string "" Database password.
OfficeServer.sql.dbName string "officecloud" Database name.
OfficeServer.sql.charset string "utf8" Database character set.
OfficeServer.sql.connectionlimit integer 10 Maximum number of connections in the pool.
OfficeServer.sql.tableChanges string "doc_changes" Document changes table name.
OfficeServer.sql.tableResult string "task_result" Task results table name.

Example:

{
  "ServicesInformation": {
    "OfficeServer": {
      "sql": {
        "type": "mysql",
        "dbHost": "127.0.0.1",
        "dbPort": 3306,
        "dbUser": "root",
        "dbPass": "your-password",
        "dbName": "officecloud",
        "charset": "utf8",
        "connectionlimit": 10,
        "tableChanges": "doc_changes",
        "tableResult": "task_result"
      }
    }
  }
}

Note

Before switching, make sure the database and tables have been created, and make sure the table names match the configuration. Keep only one of sqlite3 and sql; when using sql, remove sqlite3. Restart OfficeServer after the change.

FAQ

Documents fail to open after changing the port

Cause: Only the editor service port was changed. coAuthorUrl in the example service or the business page was not updated, so the page still connects to the old port.

Solution: Update customization.serverless.coAuthorUrl for the example service, or editorAttrs.serverless.coAuthorUrl for a business page, to the new port. Then restart the example service and reopen the page. If the page is not accessed from the server itself, also make sure the address uses the server's IP or domain name.

Configuration in default.json does not take effect

Cause: OfficeServer, the editor service, reads its configuration only at startup, so changes do not apply until the service is restarted. The JSON may also be malformed.

Solution: Make sure you edited service/OfficeServer/<platform>/config/default.json, validate the JSON, restart OfficeServer, and reopen the document to verify.

The autosave interval is not applied

Cause: autosave_interval is sent to the editor when a document is opened. Documents that are already open do not use the new value immediately, and the server does not send the interval when co-editing is not active.

Solution: Make sure you changed the server-side configuration and used milliseconds as the unit. Restart OfficeServer, reopen the document, and confirm that co-editing is in fast mode.