diff --git a/js/server/modules/@arangodb/foxx/routing.js b/js/server/modules/@arangodb/foxx/routing.js index 2be3dd31c4..aaa0567af7 100644 --- a/js/server/modules/@arangodb/foxx/routing.js +++ b/js/server/modules/@arangodb/foxx/routing.js @@ -136,11 +136,6 @@ exports.routeService = function (service, throwOnErrors) { service._reset(); - let error = null; - if (service.legacy) { - error = routeLegacyService(service, throwOnErrors); - } - const defaultDocument = service.manifest.defaultDocument; if (defaultDocument) { service.routes.routes.push({ @@ -156,6 +151,24 @@ exports.routeService = function (service, throwOnErrors) { }); } + let error = null; + if (service.legacy) { + error = routeLegacyService(service, throwOnErrors); + } else { + if (service.manifest.main) { + try { + service.main.exports = service.run(service.manifest.main); + } catch (e) { + console.errorLines(`Cannot execute Foxx service at ${service.mount}: ${e.stack}`); + error = e; + if (throwOnErrors) { + throw e; + } + } + } + service.buildRoutes(); + } + if (service.manifest.files) { const files = service.manifest.files; _.each(files, function (file, path) { @@ -177,22 +190,6 @@ exports.routeService = function (service, throwOnErrors) { }); } - if (!service.legacy) { - if (service.manifest.main) { - try { - service.main.exports = service.run(service.manifest.main); - } catch (e) { - console.errorLines(`Cannot execute Foxx service at ${service.mount}: ${e.stack}`); - error = e; - if (throwOnErrors) { - throw e; - } - } - } - - service.buildRoutes(); - } - service.main.loaded = true; return {