foxx manifest(2)
每一个foxx服务都会带一个manifest.json文件来提供元数据。manifest.json的主要内容有:
configuration(可选):定义配置参数可以让参数更好的复用。在configuration中定义的参数可以在 service context's的configuration属性下调用。参数的主要内容:
description:描述参数
type:参数类型
default:默认值
required:默认为true
示例:
"configuration": {
"currency": {
"description": "Currency symbol to use for prices in the shop.",
"default": "$",
"type": "string"
},
"secretKey": {
"description": "Secret key to use for signing session tokens.",
"type": "password"
}
}
defaultDocument(可选):
如果定义后,'/‘根目录将会自动被重定向到定义的路径
"defaultDocument": "index.html"
等价于
const createRouter = require('@arangodb/foxx/router');
const indexRouter = createRouter();
indexRouter.all('/', function (req, res) {
res.redirect('index.html');
});
module.context.use(indexRouter);
dependencies和provides
dependecies定义了本服务的依赖
provides定义了本服务可以提供的服务
engines(可选):定义该服务兼容的arangodb的版本
"engines": {
"arangodb": "^3.0.0"
}
files(可选):定义了file assets
如下:
"files": {
"/some/filename.png": {
"path": "some-local-filename.png",
"type": "image/png",
"gzip": false
},
"/favicon.ico": "bookmark.ico",
"/static": "my-assets-folder"
}
等价于:
router.get('/some/filename.png', function (req, res) {
const filePath = module.context.fileName('some-local-filename.png');
res.sendFile(filePath);
});
我们定义了一个路径,然后http请求时返回对应的资产,资产配置的主要内容有:path,路径,type:默认为扩展名类型,gzip:默认为false.
lib:默认为"."
默认为相对路径
main:服务的入口文件,当服务挂载的时候执行的文件
"main": "index.js"
这里的index.js是相对于lib的 。
scripts:
定义该服务可以提供的工作,其他服务可以通过调用命名的脚本来执行该服务。示例
{
...
"scripts": {
"setup": "scripts/setup.js",
"send-mail": "scripts/send-mail.js"
}
...
}
可以添加到队列工作中。
'use strict';
const queues = require('@arangodb/foxx/queues');
queues.get('default').push(
{mount: '/my-service-mount-point', name: 'send-mail'},
{to: 'user@example.com', body: 'Hello'}
);
tests:可以是测试文件的路径
author:作者
contributors:共享者
description:对服务的描述
keywords:服务的关键字
license:服务的授权
name:服务的名称
thumbnail:图标文件50x50 and 160x160JPEG or PNG。
version:版本号
示例:
{
"name": "example-foxx-service",
"version": "3.0.0-dev",
"license": "MIT",
"description": "An example service with a relatively full-featured manifest.",
"thumbnail": "foxx-icon.png",
"keywords": ["demo", "service"],
"author": "ArangoDB GmbH",
"contributors": [
"Alan Plum <alan@arangodb.example>"
],
"lib": "dist",
"main": "entry.js",
"defaultDocument": "welcome.html",
"engines": {
"arangodb": "^3.0.0"
},
"files": {
"welcome.html": "assets/index.html",
"hello.jpg": "assets/hello.jpg"
"world.jpg": {
"path": "assets/world.jpg",
"type": "image/jpeg",
"gzip": false
}
},
"tests": "dist/**.spec.js"
}
浙公网安备 33010602011771号