@eik/service 2.0.163 → 2.0.164
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +67 -2
- package/bin/eik-server.js +4 -1
- package/lib/main.js +24 -8
- package/package.json +5 -2
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## [2.0.164](https://github.com/eik-lib/service/compare/v2.0.163...v2.0.164) (2024-07-31)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* deprecate customSink and built-in sinks ([a1bd266](https://github.com/eik-lib/service/commit/a1bd2662d531994afcb9a591001d3100c97e8dcc))
|
7
|
+
|
1
8
|
## [2.0.163](https://github.com/eik-lib/service/compare/v2.0.162...v2.0.163) (2024-07-29)
|
2
9
|
|
3
10
|
|
package/README.md
CHANGED
@@ -1,2 +1,67 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# Eik HTTP Service
|
2
|
+
|
3
|
+
As a standalone running HTTP service exposing the Eik Service.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```
|
8
|
+
npm install @eik/service
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
This server can either be run as a Node executable, or as a Fastify plugin.
|
14
|
+
|
15
|
+
### CLI
|
16
|
+
|
17
|
+
This spins up the built-in Fastify server using configuration from your `config/` folder, or from environment variables.
|
18
|
+
|
19
|
+
```sh
|
20
|
+
npx @eik/service
|
21
|
+
```
|
22
|
+
|
23
|
+
### Fastify plugin
|
24
|
+
|
25
|
+
For a production setup, the Fastify plugin method is recommended.
|
26
|
+
|
27
|
+
```js
|
28
|
+
import fastify from 'fastify';
|
29
|
+
import Service from '@eik/service';
|
30
|
+
import SinkGoogleCloudStorage from '@eik/sink-gcs';
|
31
|
+
|
32
|
+
// Set up the Google Cloud Storage sink
|
33
|
+
// https://github.com/eik-lib/sink-gcs?tab=readme-ov-file#example
|
34
|
+
const sink = new SinkGoogleCloudStorage({
|
35
|
+
credentials: {
|
36
|
+
client_email: 'a@email.address',
|
37
|
+
private_key: '[ ...snip... ]',
|
38
|
+
projectId: 'myProject',
|
39
|
+
},
|
40
|
+
});
|
41
|
+
|
42
|
+
// Set up the Eik service as a plugin
|
43
|
+
const service = new Service({ sink });
|
44
|
+
|
45
|
+
// Set up Fastify
|
46
|
+
const app = fastify({
|
47
|
+
ignoreTrailingSlash: true,
|
48
|
+
modifyCoreObjects: false,
|
49
|
+
trustProxy: true,
|
50
|
+
});
|
51
|
+
|
52
|
+
// Register the Eik service in Fastify
|
53
|
+
app.register(service.api());
|
54
|
+
|
55
|
+
// Start the server
|
56
|
+
const run = async () => {
|
57
|
+
await service.health();
|
58
|
+
await app.listen(
|
59
|
+
service.config.get('http.port'),
|
60
|
+
service.config.get('http.address'),
|
61
|
+
);
|
62
|
+
};
|
63
|
+
|
64
|
+
run();
|
65
|
+
```
|
66
|
+
|
67
|
+
The example above shows the Google Cloud Storage sink. You can also use the [file system sink](https://github.com/eik-lib/sink-file-system), or implement the [sink interface](https://github.com/eik-lib/sink) for your own custom storage backend.
|
package/bin/eik-server.js
CHANGED
package/lib/main.js
CHANGED
@@ -5,32 +5,48 @@ import pino from 'pino';
|
|
5
5
|
import cors from '@fastify/cors';
|
6
6
|
import jwt from '@fastify/jwt';
|
7
7
|
import eik from '@eik/core';
|
8
|
+
import SinkMemory from '@eik/sink-memory';
|
9
|
+
import SinkFileSystem from '@eik/sink-file-system';
|
8
10
|
|
9
11
|
|
10
12
|
import config from './config.js';
|
11
13
|
import * as utils from './utils.js';
|
12
14
|
|
15
|
+
/**
|
16
|
+
* @typedef {object} EikServiceOptions
|
17
|
+
* @property {import('@eik/sink').default} [sink]
|
18
|
+
* @property {import('@eik/sink').default} [customSink] [Deprecated] Use sink instead
|
19
|
+
* @property {string} [aliasCacheControl]
|
20
|
+
* @property {string} [notFoundCacheControl="public, max-age=5"]
|
21
|
+
*/
|
22
|
+
|
13
23
|
const EikService = class EikService {
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
24
|
+
/**
|
25
|
+
* @param {EikServiceOptions} [options={}]
|
26
|
+
*/
|
27
|
+
constructor(options = {}) {
|
28
|
+
let { sink } = options;
|
29
|
+
const {
|
30
|
+
customSink,
|
31
|
+
notFoundCacheControl,
|
32
|
+
aliasCacheControl,
|
33
|
+
} = options;
|
19
34
|
this._notFoundCacheControl = notFoundCacheControl || 'public, max-age=5';
|
20
35
|
const logger = pino({
|
36
|
+
// @ts-ignore
|
21
37
|
level: config.get('log.level'),
|
22
38
|
name: config.get('name'),
|
23
39
|
});
|
24
40
|
|
25
|
-
let sink;
|
26
41
|
if (customSink) {
|
42
|
+
logger.warn('The `customSink` option is deprecated and will be removed at a later stage. Use `sink` to remove this warning.');
|
27
43
|
sink = customSink;
|
28
44
|
} else if (config.get('sink.type') === 'mem') {
|
29
45
|
logger.info(`Server is running with a in memory sink. Uploaded files will be lost on restart!`);
|
30
|
-
sink = new
|
46
|
+
sink = new SinkMemory();
|
31
47
|
} else {
|
32
48
|
logger.info(`Server is running with the file system sink. Uploaded files will be stored under "${config.get('sink.path')}"`);
|
33
|
-
sink = new
|
49
|
+
sink = new SinkFileSystem({ sinkFsRootPath: config.get('sink.path') });
|
34
50
|
}
|
35
51
|
|
36
52
|
// Transform organization config
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@eik/service",
|
3
|
-
"version": "2.0.
|
3
|
+
"version": "2.0.164",
|
4
4
|
"description": "Eik REST API as a standalone HTTP service",
|
5
5
|
"type": "module",
|
6
6
|
"main": "./lib/main.js",
|
@@ -33,7 +33,10 @@
|
|
33
33
|
},
|
34
34
|
"homepage": "https://github.com/eik-lib/service#readme",
|
35
35
|
"dependencies": {
|
36
|
-
"@eik/core": "1.3.
|
36
|
+
"@eik/core": "1.3.48",
|
37
|
+
"@eik/sink": "1.2.5",
|
38
|
+
"@eik/sink-file-system": "1.0.1",
|
39
|
+
"@eik/sink-memory": "1.1.1",
|
37
40
|
"@fastify/compress": "6.5.0",
|
38
41
|
"@fastify/cors": "8.5.0",
|
39
42
|
"@fastify/jwt": "7.2.4",
|