Foxx service context
Examples
The service context specifies the following properties:
argv:
any
Any arguments passed in if the current file was executed as a script or queued job.
basePath:
string
The file system path of the service, i.e. the folder in which the service was installed to by ArangoDB.
collectionPrefix:
string
The prefix that will be used by collection and collectionName to derive the names of service-specific collections. This is derived from the service’s mount point, e.g.
/my-foxx
becomesmy_foxx
.configuration:
Object
for the service.
dependencies:
Object
Configured dependencies for the service.
isDevelopment:
boolean
Indicates whether the service is running in .
isProduction:
boolean
The inverse of isDevelopment.
manifest:
Object
The parsed manifest file of the service.
mount:
The mount point of the service, e.g.
/my-foxx
.
module.context.apiDocumentation([options]): Function
DEPRECATED
Creates a request handler that serves the API documentation.
Note: This method has been deprecated in ArangoDB 3.1 and replaced with the more straightforward createDocumentationRouter
method providing the same functionality.
Arguments
See createDocumentationRouter
below.
createDocumentationRouter
module.context.createDocumentationRouter([options]): Router
Creates a router that serves the API documentation.
Note: The router can be mounted like any other child router (see examples below).
Arguments
options:
Object
(optional)An object with any of the following properties:
mount:
string
(Default:module.context.mount
)The mount path of the service to serve the documentation of.
swaggerRoot:
string
(optional)Full path of the folder containing the Swagger assets and the indexFile. Defaults to the Swagger assets used by the web interface.
before:
Function
(optional)A function that will be executed before a request is handled.
If the function returns
false
the request will not be processed any further.If the function returns an object, its attributes will be used to override the options for the current request.
Any other return value will be ignored.
If options is a function it will be used as the before option.
If options is a string it will be used as the swaggerRoot option.
Returns a Foxx router.
Examples
Passes the given name to collectionName, then looks up the collection with the prefixed name.
Arguments
name:
string
Unprefixed name of the service-specific collection.
Returns a collection or null
if no collection with the prefixed name exists.
collectionName
module.context.collectionName(name): string
Arguments
name:
string
Unprefixed name of the service-specific collection.
Returns the prefixed name.
Examples
module.context.file(name, [encoding]): Buffer | string
Passes the given name to fileName, then loads the file with the resulting name.
Arguments
name:
string
Name of the file to load, relative to the current service.
encoding:
string
(optional)Encoding of the file, e.g.
utf-8
. If omitted the file will be loaded as a raw buffer instead of a string.
Returns the file’s contents.
fileName
module.context.fileName(name): string
Resolves the given file name relative to the current service.
Arguments
name:
string
Name of the file, relative to the current service.
Returns the absolute file path.
module.context.use([path], router): Endpoint
Mounts a given router on the service to expose the router’s routes on the service’s mount point.
Arguments
path:
string
(Default:"/"
)Path to mount the router at, relative to the service’s mount point.
router:
A router or middleware to mount.
Returns an Endpoint for the given router or middleware.
Note: Mounting services at run time (e.g. within request handlers or queued jobs) is not supported.