@thzero/library_server_fastify 0.17.5 → 0.17.6
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/README.md +17 -17
- package/boot/index.js +367 -367
- package/boot/plugins/admin/news.js +11 -11
- package/boot/plugins/admin/users.js +11 -11
- package/boot/plugins/api.js +16 -16
- package/boot/plugins/apiFront.js +21 -21
- package/boot/plugins/news.js +11 -11
- package/boot/plugins/users.js +11 -11
- package/boot/plugins/usersExtended.js +6 -6
- package/license.md +8 -8
- package/middleware/authentication.js +94 -94
- package/middleware/authorization.js +220 -220
- package/openSource.js +80 -80
- package/package.json +41 -41
- package/plugins/apiKey.js +48 -48
- package/plugins/auth.js +124 -124
- package/plugins/responseTime.js +111 -111
- package/plugins/settings.js +12 -12
- package/plugins/usageMetrics.js +24 -24
- package/routes/admin/index.js +140 -140
- package/routes/admin/news.js +22 -22
- package/routes/admin/users.js +26 -26
- package/routes/baseNews.js +45 -45
- package/routes/baseUsers.js +153 -153
- package/routes/home.js +28 -28
- package/routes/index.js +41 -41
- package/routes/news.js +6 -6
- package/routes/plans.js +39 -39
- package/routes/users.js +6 -6
- package/routes/utility.js +80 -80
- package/routes/version.js +39 -39
package/plugins/settings.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import fastifyPlugin from 'fastify-plugin';
|
|
2
|
-
|
|
3
|
-
import LibraryServerConstants from '@thzero/library_server/constants.js';
|
|
4
|
-
|
|
5
|
-
export default fastifyPlugin((instance, opts, done) => {
|
|
6
|
-
instance.addHook('onRequest', (request, reply, next) => {
|
|
7
|
-
request.config = opts.config;
|
|
8
|
-
request.correlationId = request.headers[LibraryServerConstants.Headers.CorrelationId];
|
|
9
|
-
next();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
done();
|
|
1
|
+
import fastifyPlugin from 'fastify-plugin';
|
|
2
|
+
|
|
3
|
+
import LibraryServerConstants from '@thzero/library_server/constants.js';
|
|
4
|
+
|
|
5
|
+
export default fastifyPlugin((instance, opts, done) => {
|
|
6
|
+
instance.addHook('onRequest', (request, reply, next) => {
|
|
7
|
+
request.config = opts.config;
|
|
8
|
+
request.correlationId = request.headers[LibraryServerConstants.Headers.CorrelationId];
|
|
9
|
+
next();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
done();
|
|
13
13
|
});
|
package/plugins/usageMetrics.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import fastifyPlugin from 'fastify-plugin';
|
|
2
|
-
|
|
3
|
-
export default fastifyPlugin((instance, opts, done) => {
|
|
4
|
-
instance.addHook('onSend', (request, reply, payload, next) => {
|
|
5
|
-
(async () => {
|
|
6
|
-
const usageMetrics = {
|
|
7
|
-
url: request.routerPath,
|
|
8
|
-
correlationId: request.correlationId,
|
|
9
|
-
href: request.url,
|
|
10
|
-
headers: request.headers,
|
|
11
|
-
host: request.hostname,
|
|
12
|
-
hostname: request.hostname,
|
|
13
|
-
querystring: request.query,
|
|
14
|
-
token: request.token
|
|
15
|
-
};
|
|
16
|
-
await opts.usageMetrics.register(usageMetrics).catch((err) => {
|
|
17
|
-
opts.logger.error('usageMetrics', 'start', 'usageMetrics', err);
|
|
18
|
-
});
|
|
19
|
-
})();
|
|
20
|
-
|
|
21
|
-
next();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
done();
|
|
1
|
+
import fastifyPlugin from 'fastify-plugin';
|
|
2
|
+
|
|
3
|
+
export default fastifyPlugin((instance, opts, done) => {
|
|
4
|
+
instance.addHook('onSend', (request, reply, payload, next) => {
|
|
5
|
+
(async () => {
|
|
6
|
+
const usageMetrics = {
|
|
7
|
+
url: request.routerPath,
|
|
8
|
+
correlationId: request.correlationId,
|
|
9
|
+
href: request.url,
|
|
10
|
+
headers: request.headers,
|
|
11
|
+
host: request.hostname,
|
|
12
|
+
hostname: request.hostname,
|
|
13
|
+
querystring: request.query,
|
|
14
|
+
token: request.token
|
|
15
|
+
};
|
|
16
|
+
await opts.usageMetrics.register(usageMetrics).catch((err) => {
|
|
17
|
+
opts.logger.error('usageMetrics', 'start', 'usageMetrics', err);
|
|
18
|
+
});
|
|
19
|
+
})();
|
|
20
|
+
|
|
21
|
+
next();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
done();
|
|
25
25
|
});
|
package/routes/admin/index.js
CHANGED
|
@@ -1,140 +1,140 @@
|
|
|
1
|
-
import BaseRoute from '../index.js';
|
|
2
|
-
|
|
3
|
-
class AdminBaseRoute extends BaseRoute {
|
|
4
|
-
constructor(urlFragment, role, serviceKey) {
|
|
5
|
-
if (!urlFragment)
|
|
6
|
-
throw Error('Invalid url fragment');
|
|
7
|
-
|
|
8
|
-
super(`/admin/${urlFragment}`);
|
|
9
|
-
|
|
10
|
-
this._options = {
|
|
11
|
-
role: role,
|
|
12
|
-
serviceKey: serviceKey
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// this._service = null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async init(injector, app, config) {
|
|
19
|
-
await super.init(injector, app, config);
|
|
20
|
-
this._inject(app, injector, this._options.serviceKey, this._options.serviceKey);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
_allowsCreate() {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
_allowsDelete() {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
_allowsUpdate() {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
_initializeRoutesCreate(router) {
|
|
36
|
-
const self = this;
|
|
37
|
-
router.post(this._join(''),
|
|
38
|
-
// authentication(true),
|
|
39
|
-
// authorization([ `${self._options.role}.create` ]),
|
|
40
|
-
{
|
|
41
|
-
preHandler: router.auth([
|
|
42
|
-
router.authenticationDefault,
|
|
43
|
-
router.authorizationDefault
|
|
44
|
-
],
|
|
45
|
-
{
|
|
46
|
-
relation: 'and',
|
|
47
|
-
roles: [ `${self._options.role}.create` ]
|
|
48
|
-
}),
|
|
49
|
-
},
|
|
50
|
-
// eslint-disable-next-line
|
|
51
|
-
async (request, reply) => {
|
|
52
|
-
const response = (await router[this._options.serviceKey].create(request.correlationId, request.user, request.body)).check(request);
|
|
53
|
-
// https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
|
|
54
|
-
return this._jsonResponse(reply, response);
|
|
55
|
-
}
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
_initializeRoutesDelete(router) {
|
|
60
|
-
router.delete(this._join('/:id'),
|
|
61
|
-
// authentication(true),
|
|
62
|
-
// authorization([ `${this._options.role}.delete` ]),
|
|
63
|
-
{
|
|
64
|
-
preHandler: router.auth([
|
|
65
|
-
router.authenticationDefault,
|
|
66
|
-
router.authorizationDefault
|
|
67
|
-
],
|
|
68
|
-
{
|
|
69
|
-
relation: 'and',
|
|
70
|
-
roles: [ `${this._options.role}.delete` ]
|
|
71
|
-
}),
|
|
72
|
-
},
|
|
73
|
-
// eslint-disable-next-line
|
|
74
|
-
async (request, reply) => {
|
|
75
|
-
const response = (await router[this._options.serviceKey].delete(request.correlationId, request.user, request.params.id)).check(request);
|
|
76
|
-
// https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
|
|
77
|
-
return this._jsonResponse(reply, response);
|
|
78
|
-
}
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
_initializeRoutesUpdate(router) {
|
|
83
|
-
router.post(this._join('/:id'),
|
|
84
|
-
// authentication(true),
|
|
85
|
-
// authorization([ `${this._options.role}.update` ]),
|
|
86
|
-
{
|
|
87
|
-
preHandler: router.auth([
|
|
88
|
-
router.authenticationDefault,
|
|
89
|
-
router.authorizationDefault
|
|
90
|
-
],
|
|
91
|
-
{
|
|
92
|
-
relation: 'and',
|
|
93
|
-
roles: [ `${this._options.role}.update` ]
|
|
94
|
-
}),
|
|
95
|
-
},
|
|
96
|
-
// eslint-disable-next-line
|
|
97
|
-
async (request, reply) => {
|
|
98
|
-
const response = (await router[this._options.serviceKey].update(request.correlationId, request.user, request.params.id, request.body)).check(request);
|
|
99
|
-
// https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
|
|
100
|
-
return this._jsonResponse(reply, response);
|
|
101
|
-
}
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
_initializeRoutes(router) {
|
|
106
|
-
if (this._allowsDelete)
|
|
107
|
-
this._initializeRoutesDelete(router);
|
|
108
|
-
|
|
109
|
-
router.post(this._join('/search'),
|
|
110
|
-
// authentication(true),
|
|
111
|
-
// authorization([ `${this._options.role}.search` ]),
|
|
112
|
-
{
|
|
113
|
-
preHandler: router.auth([
|
|
114
|
-
router.authenticationDefault,
|
|
115
|
-
router.authorizationDefault
|
|
116
|
-
],
|
|
117
|
-
{
|
|
118
|
-
relation: 'and',
|
|
119
|
-
roles: [ `${this._options.role}.search` ]
|
|
120
|
-
}),
|
|
121
|
-
},
|
|
122
|
-
// eslint-disable-next-line
|
|
123
|
-
async (request, reply) => {
|
|
124
|
-
const response = (await router[this._options.serviceKey].search(request.correlationId, request.user, request.body)).check(request);
|
|
125
|
-
// https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
|
|
126
|
-
return this._jsonResponse(reply, response);
|
|
127
|
-
}
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
if (this._allowsUpdate())
|
|
131
|
-
this._initializeRoutesUpdate(router);
|
|
132
|
-
|
|
133
|
-
if (this._allowsCreate())
|
|
134
|
-
this._initializeRoutesCreate(router);
|
|
135
|
-
|
|
136
|
-
return router;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export default AdminBaseRoute;
|
|
1
|
+
import BaseRoute from '../index.js';
|
|
2
|
+
|
|
3
|
+
class AdminBaseRoute extends BaseRoute {
|
|
4
|
+
constructor(urlFragment, role, serviceKey) {
|
|
5
|
+
if (!urlFragment)
|
|
6
|
+
throw Error('Invalid url fragment');
|
|
7
|
+
|
|
8
|
+
super(`/admin/${urlFragment}`);
|
|
9
|
+
|
|
10
|
+
this._options = {
|
|
11
|
+
role: role,
|
|
12
|
+
serviceKey: serviceKey
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// this._service = null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async init(injector, app, config) {
|
|
19
|
+
await super.init(injector, app, config);
|
|
20
|
+
this._inject(app, injector, this._options.serviceKey, this._options.serviceKey);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
_allowsCreate() {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
_allowsDelete() {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
_allowsUpdate() {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
_initializeRoutesCreate(router) {
|
|
36
|
+
const self = this;
|
|
37
|
+
router.post(this._join(''),
|
|
38
|
+
// authentication(true),
|
|
39
|
+
// authorization([ `${self._options.role}.create` ]),
|
|
40
|
+
{
|
|
41
|
+
preHandler: router.auth([
|
|
42
|
+
router.authenticationDefault,
|
|
43
|
+
router.authorizationDefault
|
|
44
|
+
],
|
|
45
|
+
{
|
|
46
|
+
relation: 'and',
|
|
47
|
+
roles: [ `${self._options.role}.create` ]
|
|
48
|
+
}),
|
|
49
|
+
},
|
|
50
|
+
// eslint-disable-next-line
|
|
51
|
+
async (request, reply) => {
|
|
52
|
+
const response = (await router[this._options.serviceKey].create(request.correlationId, request.user, request.body)).check(request);
|
|
53
|
+
// https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
|
|
54
|
+
return this._jsonResponse(reply, response);
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
_initializeRoutesDelete(router) {
|
|
60
|
+
router.delete(this._join('/:id'),
|
|
61
|
+
// authentication(true),
|
|
62
|
+
// authorization([ `${this._options.role}.delete` ]),
|
|
63
|
+
{
|
|
64
|
+
preHandler: router.auth([
|
|
65
|
+
router.authenticationDefault,
|
|
66
|
+
router.authorizationDefault
|
|
67
|
+
],
|
|
68
|
+
{
|
|
69
|
+
relation: 'and',
|
|
70
|
+
roles: [ `${this._options.role}.delete` ]
|
|
71
|
+
}),
|
|
72
|
+
},
|
|
73
|
+
// eslint-disable-next-line
|
|
74
|
+
async (request, reply) => {
|
|
75
|
+
const response = (await router[this._options.serviceKey].delete(request.correlationId, request.user, request.params.id)).check(request);
|
|
76
|
+
// https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
|
|
77
|
+
return this._jsonResponse(reply, response);
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
_initializeRoutesUpdate(router) {
|
|
83
|
+
router.post(this._join('/:id'),
|
|
84
|
+
// authentication(true),
|
|
85
|
+
// authorization([ `${this._options.role}.update` ]),
|
|
86
|
+
{
|
|
87
|
+
preHandler: router.auth([
|
|
88
|
+
router.authenticationDefault,
|
|
89
|
+
router.authorizationDefault
|
|
90
|
+
],
|
|
91
|
+
{
|
|
92
|
+
relation: 'and',
|
|
93
|
+
roles: [ `${this._options.role}.update` ]
|
|
94
|
+
}),
|
|
95
|
+
},
|
|
96
|
+
// eslint-disable-next-line
|
|
97
|
+
async (request, reply) => {
|
|
98
|
+
const response = (await router[this._options.serviceKey].update(request.correlationId, request.user, request.params.id, request.body)).check(request);
|
|
99
|
+
// https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
|
|
100
|
+
return this._jsonResponse(reply, response);
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
_initializeRoutes(router) {
|
|
106
|
+
if (this._allowsDelete)
|
|
107
|
+
this._initializeRoutesDelete(router);
|
|
108
|
+
|
|
109
|
+
router.post(this._join('/search'),
|
|
110
|
+
// authentication(true),
|
|
111
|
+
// authorization([ `${this._options.role}.search` ]),
|
|
112
|
+
{
|
|
113
|
+
preHandler: router.auth([
|
|
114
|
+
router.authenticationDefault,
|
|
115
|
+
router.authorizationDefault
|
|
116
|
+
],
|
|
117
|
+
{
|
|
118
|
+
relation: 'and',
|
|
119
|
+
roles: [ `${this._options.role}.search` ]
|
|
120
|
+
}),
|
|
121
|
+
},
|
|
122
|
+
// eslint-disable-next-line
|
|
123
|
+
async (request, reply) => {
|
|
124
|
+
const response = (await router[this._options.serviceKey].search(request.correlationId, request.user, request.body)).check(request);
|
|
125
|
+
// https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
|
|
126
|
+
return this._jsonResponse(reply, response);
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
if (this._allowsUpdate())
|
|
131
|
+
this._initializeRoutesUpdate(router);
|
|
132
|
+
|
|
133
|
+
if (this._allowsCreate())
|
|
134
|
+
this._initializeRoutesCreate(router);
|
|
135
|
+
|
|
136
|
+
return router;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export default AdminBaseRoute;
|
package/routes/admin/news.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import LibraryServerConstants from '@thzero/library_server/constants.js';
|
|
2
|
-
|
|
3
|
-
import AdminRoute from './index.js';
|
|
4
|
-
|
|
5
|
-
class NewsAdminRoute extends AdminRoute {
|
|
6
|
-
constructor(urlFragment, role, serviceKey) {
|
|
7
|
-
urlFragment = urlFragment ? urlFragment : 'news';
|
|
8
|
-
role = role ? role : 'news';
|
|
9
|
-
serviceKey = serviceKey ? serviceKey : LibraryServerConstants.InjectorKeys.SERVICE_ADMIN_NEWS;
|
|
10
|
-
super(urlFragment, role, serviceKey);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
get id() {
|
|
14
|
-
return 'admin-news';
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
get _version() {
|
|
18
|
-
return 'v1';
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default NewsAdminRoute;
|
|
1
|
+
import LibraryServerConstants from '@thzero/library_server/constants.js';
|
|
2
|
+
|
|
3
|
+
import AdminRoute from './index.js';
|
|
4
|
+
|
|
5
|
+
class NewsAdminRoute extends AdminRoute {
|
|
6
|
+
constructor(urlFragment, role, serviceKey) {
|
|
7
|
+
urlFragment = urlFragment ? urlFragment : 'news';
|
|
8
|
+
role = role ? role : 'news';
|
|
9
|
+
serviceKey = serviceKey ? serviceKey : LibraryServerConstants.InjectorKeys.SERVICE_ADMIN_NEWS;
|
|
10
|
+
super(urlFragment, role, serviceKey);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
get id() {
|
|
14
|
+
return 'admin-news';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get _version() {
|
|
18
|
+
return 'v1';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default NewsAdminRoute;
|
package/routes/admin/users.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import LibraryServerConstants from '@thzero/library_server/constants.js';
|
|
2
|
-
|
|
3
|
-
import AdminRoute from './index.js';
|
|
4
|
-
|
|
5
|
-
class UsersAdminRoute extends AdminRoute {
|
|
6
|
-
constructor(urlFragment, role, serviceKey) {
|
|
7
|
-
urlFragment = urlFragment ? urlFragment : 'users';
|
|
8
|
-
role = role ? role : 'users';
|
|
9
|
-
serviceKey = serviceKey ? serviceKey : LibraryServerConstants.InjectorKeys.SERVICE_ADMIN_USERS;
|
|
10
|
-
super(urlFragment, role, serviceKey);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
get id() {
|
|
14
|
-
return 'admin-users';
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
_allowsCreate() {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
get _version() {
|
|
22
|
-
return 'v1';
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default UsersAdminRoute;
|
|
1
|
+
import LibraryServerConstants from '@thzero/library_server/constants.js';
|
|
2
|
+
|
|
3
|
+
import AdminRoute from './index.js';
|
|
4
|
+
|
|
5
|
+
class UsersAdminRoute extends AdminRoute {
|
|
6
|
+
constructor(urlFragment, role, serviceKey) {
|
|
7
|
+
urlFragment = urlFragment ? urlFragment : 'users';
|
|
8
|
+
role = role ? role : 'users';
|
|
9
|
+
serviceKey = serviceKey ? serviceKey : LibraryServerConstants.InjectorKeys.SERVICE_ADMIN_USERS;
|
|
10
|
+
super(urlFragment, role, serviceKey);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
get id() {
|
|
14
|
+
return 'admin-users';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
_allowsCreate() {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get _version() {
|
|
22
|
+
return 'v1';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default UsersAdminRoute;
|
package/routes/baseNews.js
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import LibraryServerConstants from '@thzero/library_server/constants.js';
|
|
2
|
-
|
|
3
|
-
import BaseRoute from './index.js';
|
|
4
|
-
|
|
5
|
-
class BaseNewsRoute extends BaseRoute {
|
|
6
|
-
constructor(prefix, version) {
|
|
7
|
-
super(prefix ? prefix : '/news');
|
|
8
|
-
|
|
9
|
-
// this._serviceNews = null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async init(injector, app, config) {
|
|
13
|
-
await super.init(injector, app, config);
|
|
14
|
-
// this._serviceNews = injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_NEWS);
|
|
15
|
-
this._inject(app, injector, LibraryServerConstants.InjectorKeys.SERVICE_NEWS, LibraryServerConstants.InjectorKeys.SERVICE_NEWS);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get id() {
|
|
19
|
-
return 'news';
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
_initializeRoutes(router) {
|
|
23
|
-
router.get(this._join('/latest/:date'),
|
|
24
|
-
// authentication(false),
|
|
25
|
-
{
|
|
26
|
-
preHandler: router.auth([
|
|
27
|
-
router.authenticationDefault,
|
|
28
|
-
// router.authorizationDefault
|
|
29
|
-
],
|
|
30
|
-
{
|
|
31
|
-
relation: 'and',
|
|
32
|
-
required: false,
|
|
33
|
-
roles: [ 'news' ]
|
|
34
|
-
}),
|
|
35
|
-
},
|
|
36
|
-
async (request, reply) => {
|
|
37
|
-
// const service = this._injector.getService(ServerConstants.InjectorKeys.SERVICE_NEWS);
|
|
38
|
-
const response = (await router[ServerConstants.InjectorKeys.SERVICE_NEWS].latest(request.correlationId, request.user, parseInt(request.params.date))).check(request);
|
|
39
|
-
// https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
|
|
40
|
-
return this._jsonResponse(reply, response);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export default BaseNewsRoute;
|
|
1
|
+
import LibraryServerConstants from '@thzero/library_server/constants.js';
|
|
2
|
+
|
|
3
|
+
import BaseRoute from './index.js';
|
|
4
|
+
|
|
5
|
+
class BaseNewsRoute extends BaseRoute {
|
|
6
|
+
constructor(prefix, version) {
|
|
7
|
+
super(prefix ? prefix : '/news');
|
|
8
|
+
|
|
9
|
+
// this._serviceNews = null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async init(injector, app, config) {
|
|
13
|
+
await super.init(injector, app, config);
|
|
14
|
+
// this._serviceNews = injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_NEWS);
|
|
15
|
+
this._inject(app, injector, LibraryServerConstants.InjectorKeys.SERVICE_NEWS, LibraryServerConstants.InjectorKeys.SERVICE_NEWS);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get id() {
|
|
19
|
+
return 'news';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
_initializeRoutes(router) {
|
|
23
|
+
router.get(this._join('/latest/:date'),
|
|
24
|
+
// authentication(false),
|
|
25
|
+
{
|
|
26
|
+
preHandler: router.auth([
|
|
27
|
+
router.authenticationDefault,
|
|
28
|
+
// router.authorizationDefault
|
|
29
|
+
],
|
|
30
|
+
{
|
|
31
|
+
relation: 'and',
|
|
32
|
+
required: false,
|
|
33
|
+
roles: [ 'news' ]
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
async (request, reply) => {
|
|
37
|
+
// const service = this._injector.getService(ServerConstants.InjectorKeys.SERVICE_NEWS);
|
|
38
|
+
const response = (await router[ServerConstants.InjectorKeys.SERVICE_NEWS].latest(request.correlationId, request.user, parseInt(request.params.date))).check(request);
|
|
39
|
+
// https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
|
|
40
|
+
return this._jsonResponse(reply, response);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default BaseNewsRoute;
|