XF 2.1 Problem when deploying custom addon with custom rest api endpoints on my live site

Cylon

Member
Dear Friends,

I'm newbie to XF addon development, and I'm having a problem with my first addon. This add-on extends the XF Rest API by adding a couple of custom endpoints for my special needs.

I developed and tested the addon, on my local development environment, consisting of PhpStorm on windows, and a virtual machine that replicates my production server (UBuntu 18.04, PHP 7.2). The only difference between the virtual machine and the production server, is that the virtual machine has the php remote debug features enabled and opcache disabled (well there are a couple of differences more, for example, I'm not using a firewall on the virtual machine, but I don't think this is relevant).

The strange thing is that the endpoint that I developed, is working very well in my local environment. But when I install the addon on the server, it does not work. The addon is installed without errors. The endpoints and custom classes extensions are added (I checked it in the development panel). But when my client app calls the endpoints, I receive following error message:

"errors": [
{
"code": "endpoint_not_found",
"message": "Requested endpoint not found.",
"params": {
"reason": "invalid_route"
}
}
]
}

Of course, the client app is calling the same custom endpoint with the same action verb that it is calling on my development server. I'm not sure, but I think that the routing works and the COntroller is reached, but not the method (function) that I'm calling.

I double-checked the API keys, the permissions of the files in the folder, the url that are called, deleted and installed the addon again... I'm running out of ideas. No error messages are logged neither in XF, or in the Linux log files...

Maybe you can offer me some advice.

Thanks in advance.
 
I created an installation package with the tool
php cmd.php xf-addon:build-release

And then I uploaded the generated zip file through the admin section. It was uploaded and installed without errors...
 
The invalid route error means the route isn’t in the database. Did you create custom routes in your add on? If so, are they definitely associated with the add on (it’s not difficult to associate new items with the wrong add on).

If not, and you’re using a built in route, you should try rebuilding master data (this can be done from the command line tool, or by going to the installer directory).
 
Dear Friends,

thank you for your suggestions. It works now, but sadly, I don't know exactly why. I yes I know why, but I can not believe that this little change is the difference between working and not.

The route for my plugin is like the following:

src/addons/MyCompany/MyPlugin

In this folder I had the following subfolders:

src/addons/MyCompany/MyPlugin/api/controller
src/addons/MyCompany/MyPlugin/api/helpers
src/addons/MyCompany/MyPlugin/Entity
src/addons/MyCompany/MyPlugin/Repository
src/addons/MyCompany/MyPlugin/Finder

In my controller folder, I had two controllers

src/addons/MyCompany/MyPlugin/api/controller/Controller1.php
src/addons/MyCompany/MyPlugin/api/controller/Controller2.php

with the following namespaces:

namespace MyCompany\MyPlugin\api\controller;

Then under Development->Class Extensions I added entries for the controllers, and under Development->Routes->Api, I added entries for the new routes/endpoints of my custom controllers.

This was working perfectly on my local development environment, but as said, not on the production server.

The only thing I changed was:

1.- The folders from src/addons/MyCompany/MyPlugin/api/controller to src/addons/MyCompany/MyPlugin/Api/Controller

2.- and the namespaces from namespace MyCompany\MyPlugin\api\controller; to namespace MyCompany\MyPlugin\Api\Controller;

3.- Recreated the class extensions under Development->Class extensions. I created a new build release, uninstalled the previous plugin from the server, and installed the new one. And it works.

I suppose that the namespaces and folders should begin with a capital letter, but I don't remember reading it in the documentation...

Thank you anyway for your help...
 
Most likely your development environment has a case insensitive file system and your server a case sensitive file system.

XenForo builds the file path of files to load based on the namespace. It uses it as the literal value; and on case sensitive file systems files that differ only in case are treated as distinct files.
 
Actually, yeah, that error would cause a class not found error. I’m trying to do 45 things at once and I’m on my phone...

I have a feeling the original release didn’t have the routes in it, for whatever reason (likely as the original routes weren’t associated with the add on).
 
Most likely your development environment has a case insensitive file system and your server a case sensitive file system.

XenForo builds the file path of files to load based on the namespace. It uses it as the literal value; and on case sensitive file systems files that differ only in case are treated as distinct files.

Exactly because of problems like that I abandoned wamp and the like to do php development, and now I run all my php projects on virtual machines that are as much as similar as the productions environment as possible (with help from vagrant)

In this case, as said, an Ubuntu server v 18.04. Linux paths are always case sensitive, if that was the case, I don't understand how it has worked on the development environment.

But it is working now, thank you very much for your help, and my best wishes for this festive season.
 
Top Bottom