问题
Using ArangoDB documentation version 3.3 or version 3.4 for the Getting Started section of Foxx Microservices, I can't get past this error:
Failed to load API definition.
NetworkError when attempting to fetch resource. http://192.168.1.1:8529/_db/_system/_admin/aardvark/foxxes/docs/swagger.json?mount=/getting-started
That error is shown on the API tab of the service. After installing my service according to the tutorial, I get the service's card as described. I click that card and then click the API tab and the above error is shown.
To eliminate typos, I have tried copying and pasting the exact file contents from the ArangoDB documentation and following every step exactly, and I still get the same error.
The Info tab of my newly created getting-started
service contains this info:
Author:
Mount: /getting-started
Mode: Development
Version: Unknown
Version License: Unknown License
Path: /var/lib/arangodb3-apps/_db/_system/getting-started/APP
The example contains only two files and they are:
manifest.json
{
"engines": {
"arangodb": "^3.0.0"
},
"main": "index.js"
}
index.js
'use strict';
const createRouter = require('@arangodb/foxx/router');
const router = createRouter();
module.context.use(router);
router.get('/hello-world', function (req, res) {
res.send('Hello World!');
})
.response(['text/plain'], 'A generic greeting.')
.summary('Generic greeting')
.description('Prints a generic greeting.');
The canned demo services, such as the hello-fox example, work correctly. I collected more error information:
Navigating to http://192.168.1.1:8529/getting-started
404: errorMessage "unknown path '/getting-started'"
Navigating to http://192.168.1.1:8529/_db/_system/getting-started
404: errorMessage "unknown path '/getting-started'"
The console also shows:
WARNING File not found "/getting-started": file "" does not exist in "/var/lib/arangodb3-apps/_db/_system/getting-started/APP/files".
The tutorial doesn't indicate another file named getting-started
or another location for the two specified files. What am I missing?
回答1:
This issue was resolved based on the helpful comments by @camba1. There was no problem with Arango, just a problem with me understanding the tutorial. For others in my position, here are the things I did not understand properly and that, when addressed, resolved my problems.
The API tab, in contrast to what the tutorial says, will give the error "Failed to load API definition" even for a correctly working service. Ignore that error message. I am not yet using the API tab at all.
the tutorial refers to two paths, '/hello-world' and '/getting-started'. These are used on the endpoint (URI) and in creating the router like below:
router.get('/hello-world', function (req, res) { ...
The tutorial wasn't as clear as it could have been on this point, but as @camba1 pointed out, the service endpoint would end up incorporating both of those elements:
192.168.1.1:8529/_db/_system/getting-started/hello-world .
this very basic demo is easier and better in my opinion when the router is created without a path:
router.get(function (req, res) {
In this case it defaults to a path of '/'. I think this may avoid confusion for raw beginners like me. The service endpoint then becomes one element simpler. In my case, the endpoint (with Arango running on another computer on the LAN) becomes:
192.168.1.1:8529/_db/_system/getting-started
The tutorial would be improved if it either added a couple extra sentences to explain how the endpoint is constructed, or alternatively, did as I suggested above and simplified things by one step.
来源:https://stackoverflow.com/questions/53840307/arangodb-getting-started-with-foxx-microservices-404-errormessage-unknown-pa