Try the fastest and simplest way to install ONLYOFFICE

testing and debugging a plugin for the docEditor

Any issues about docs (uploading, editing and etc.)

testing and debugging a plugin for the docEditor

Postby robertotomas » Wed Sep 27, 2017 2:42 pm

I need to write and debug a little plugin to allow pasting of arbitrary data from rich user interfaces outside of the editor window, in the docEditor for the web (with a documentserve backend).

I have onlyoffice installed via docker and everything seems fine (yeay!). I also have a test webserver runnning (both are local, on my mac).

My webserver has a static directory serving "default.docx" which I can load with the docEditor. However, the editor is not functional yet, and I think the problem is the callback. Here's what happens when I load the page:

Image

Here is how I am mounting the document editor:

Code: Select all
import uuid from 'uuid-v4'

const document = {
    fileType: "doc",
    key: uuid(),
    title: "default.docx",
    url: 'http://localhost:8080/static/default.docx',
}
//...
    mountDocument () {
        let docEditor = new DocsAPI.DocEditor('onlyoffice', {
            document,
            documentType: 'text',
//            editorConfig: {
//                callbackUrl: 'not sure what this is or if I need it'
//            },
//              plugins: {
//                  pluginsData: [
//                      "webserver or oodoc-server? /onlyoffice/addTag/config.json"
//                  ]
//              }
        })
        window.Asc = docEditor
    }


And here is what my docserver looks like:
Code: Select all
Roberts-MBP:oo robertotomas$ docker ps
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                           NAMES
a4c54b1f27e5        onlyoffice/documentserver   "/bin/sh -c 'bash ..."   About an hour ago   Up About an hour    443/tcp, 0.0.0.0:8008->80/tcp   eager_hoover
Roberts-MBP:oo robertotomas$ cat ~/docker.oods.sh
# sudo this
docker run -i -t -d -p 8008:80 --restart=always \
  -v /app/onlyoffice/DocumentServer/logs:/var/log/onlyoffice \
  -v /app/onlyoffice/DocumentServer/data:/var/www/onlyoffice/Data \
  -v /app/onlyoffice/DocumentServer/lib:/var/lib/onlyoffice \
  -v /app/onlyoffice/DocumentServer/db:/var/lib/postgresql \
  onlyoffice/documentserver

Image
robertotomas
 
Posts: 17
Joined: Thu Aug 31, 2017 4:05 pm

Re: testing and debugging a plugin for the docEditor

Postby Maxim » Thu Sep 28, 2017 8:32 am

Hello robertotomas!
1. See error "Download failed" - url: 'http://localhost:8080/static/default.docx' - why localhost?
2. callbackUrl: 'not sure what this is or if I need it' - See here,
Maxim
 
Posts: 1179
Joined: Tue Oct 11, 2016 2:34 pm

Re: testing and debugging a plugin for the docEditor

Postby robertotomas » Thu Sep 28, 2017 12:33 pm

@Maxim - thank you for your help. especially with my previous post, that was really helpful.

edit: please note I have resolved my issues! this was written before..

regarding #1, "document failed",

I was just being explicit. Changing the code to:
Code: Select all
const document = {
    fileType: "doc",
    key: uuid(),
    title: "default.docx",
    url: '/static/default.docx',
}

does not resolve the error unfortunately.

if I point the browser directly to that url, it downloads the default.docx file .. it is globally accessible. In the documentation it says
"Check if the link to the file specified in the document.url is correct. The link must be accessible from the document editing service."
(emphasis added)
What is this document editing service? Maybe the problem is that the whole service is missing? I only set up the DocumentServer on the backend.

I had not realized that I needed the callback url set up. I created the default express app as a docker container: https://hub.docker.com/r/robertotomas/oocbh/

This listens at 8088:
Code: Select all
'use strict';

const callbackUrl = require('./index');

const express = require('express');

// Constants
const PORT = 8088;
const HOST = '0.0.0.0';

// App
const app = express();
app.get('/', (req, res) => {
  res.send('Hello world\n');
});

callbackUrl(app)

app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);

Code: Select all
var fs = require("fs");

const callbackUrl  = function (app) {

   app.post("/track", function (req, res) {

       var updateFile = function (response, body, path) {
           if (body.status == 2)
           {
               var file = syncRequest("GET", body.url);
               fs.writeFileSync(path, file.getBody());
           }

           response.write("{\"error\":0}");
           response.end();
       }

       var readbody = function (request, response, path) {
           var content = "";
           request.on("data", function (data) {
               content += data;
           });
           request.on("end", function () {
               var body = JSON.parse(content);
               updateFile(response, body, path);
           });
       }

       if (req.body.hasOwnProperty("status")) {
           updateFile(res, req.body, pathForSave);
       } else {
           readbody(req, res, pathForSave)
       }
   });
   
}

module.exports = callbackUrl


And it builds and runs fine:

Code: Select all
Roberts-MBP:callbackHandler robertotomas$ docker ps
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                           NAMES
5cb34dd56bfa        robertotomas/oocbh          "npm start"              6 seconds ago       Up 4 seconds        0.0.0.0:49160->8088/tcp         objective_wing
a4c54b1f27e5        onlyoffice/documentserver   "/bin/sh -c 'bash ..."   23 hours ago        Up 23 hours         443/tcp, 0.0.0.0:8008->80/tcp   eager_hoover
54cbcfd2a816        mysql:5.7                   "docker-entrypoint..."   37 hours ago        Up 37 hours         3306/tcp                        onlyoffice-mysql-server


I also see "hello world" at 8088.. so all is good.

I changed the documentEditor setup appropriately (I think):

Code: Select all
        let docEditor = new DocsAPI.DocEditor('onlyoffice', {
            document,
            documentType: 'text',
            editorConfig: {
                callbackUrl: 'http://localhost:8088/track/' // I have also tried 'http://localhost:8088/'
            },
//              plugins: {
//                  pluginsData: [
//                      "http://wbf.dev.qwireclear.com/static/onlyoffice/addTag/config.json"
//                  ]
//              }
        })
        window.Asc = docEditor


However, I still see both errors.
Last edited by robertotomas on Thu Sep 28, 2017 5:33 pm, edited 1 time in total.
robertotomas
 
Posts: 17
Joined: Thu Aug 31, 2017 4:05 pm

Re: testing and debugging a plugin for the docEditor

Postby robertotomas » Thu Sep 28, 2017 3:24 pm

edit: please note I have resolved my issues! this was written before. ngrok must be correctly set up, your service must own its ports, and the callbackhandler must be on the same docker image as the webserver if the file is served from the webserver.

On advice from a friend I set up the servers through port forwarding (with ngrok), so they have external urls. Then I changed the configuration files to point to the port-forwarded external urls. The "download failed" error is gone! However, the other error continues.

The only transaction errors I am seeing in the network tab of the console are coming from:

Request URL:https://localhost:8080/sockjs-node/info?t=1506611450769

with Request headers:

Request Headers
Provisional headers are shown
Origin:https://8f2831ff.ngrok.io
Referer:https://8f2831ff.ngrok.io/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36


The ngrok.io url is the temporary url for port-forwarding that the dev server is at: ie, index.html, loading the document editor is there. I expected, if there was a network error, to see an error related to localhost:8088 or localhost:8008 (or rather, the ngrok.io urls pointing to those services). So its a surprise.

In any case, my oocbh docker image, using the server from the documentation, is not working. A variant of that, which just always responds back with the json `{"error": 0}`, also does not work. Apparently more needs to be in the server before the error popup will go away. Is there a complete minimal node server somewhere that I could use?
robertotomas
 
Posts: 17
Joined: Thu Aug 31, 2017 4:05 pm


Return to Documents

Who is online

Users browsing this forum: No registered users and 1 guest