@eik/服务
这是 HTTP 服务器 运行 Eik 服务 .
执行《公约》和 HTTP 终点 包含 @eik/core。 。 。 .
安装
npm install @eik/service
使用量
此服务器可以作为节点可执行文件运行,也可以作为快取插件运行.
国 际
使用您的配置旋转内置快取服务器 config/ 文件夹,或来自环境变量.
npx @eik/service
快捷插件
对于生产设置,建议采用快取插件方法.
import fastify from 'fastify';
import Service from '@eik/service';
import SinkGoogleCloudStorage from '@eik/sink-gcs';
// Set up the Google Cloud Storage sink
// https://github.com/eik-lib/sink-gcs?tab=readme-ov-file#example
const sink = new SinkGoogleCloudStorage({
credentials: {
client_email: '[email protected]',
private_key: '[ ...snip... ]',
projectId: 'myProject',
},
});
// Set up the Eik service as a plugin
const service = new Service({ sink });
// Set up Fastify
const app = fastify({
ignoreTrailingSlash: true,
modifyCoreObjects: false,
trustProxy: true,
});
// Register the Eik service in Fastify
app.register(service.api());
// Start the server
const run = async () => {
await service.health();
await app.listen(
service.config.get('http.port'),
service.config.get('http.address'),
);
};
run();