@@ -20,8 +20,8 @@ import {
20
20
} from 'movex-master' ;
21
21
import { delay , isOneOf } from './util' ;
22
22
23
- const pkgVersion = require ( '../../package.json' ) . version ;
24
-
23
+ import { version as pkgVersion } from '../../package.json' ;
24
+ import { ResourceIdentifier } from 'movex-core-util' ;
25
25
const logsy = globalLogsy . withNamespace ( '[MovexServer]' ) ;
26
26
27
27
logsy . onLog ( ( event ) => {
@@ -144,22 +144,32 @@ export const movexServer = <TDefinition extends MovexDefinition>(
144
144
// });
145
145
146
146
app . get ( '/api/resources/:rid' , async ( req , res ) => {
147
- const rawRid = req . params . rid ;
147
+ const rawRid = req . params . rid as ResourceIdentifier <
148
+ Extract < keyof TDefinition [ 'resources' ] , string >
149
+ > ;
148
150
149
151
if ( ! isResourceIdentifier ( rawRid ) ) {
150
152
return res . sendStatus ( 400 ) ; // Bad Request
151
153
}
152
154
153
155
const ridObj = toResourceIdentifierObj ( rawRid ) ;
154
156
155
- if ( ! isOneOf ( ridObj . resourceType , objectKeys ( definition . resources ) ) ) {
157
+ if (
158
+ ! isOneOf (
159
+ ridObj . resourceType ,
160
+ objectKeys ( definition . resources ) as Extract <
161
+ keyof TDefinition [ 'resources' ] ,
162
+ string
163
+ > [ ]
164
+ )
165
+ ) {
156
166
return res . sendStatus ( 400 ) ; // Bad Request
157
167
}
158
168
159
169
res . header ( 'Content-Type' , 'application/json' ) ;
160
170
161
171
return store
162
- . get ( rawRid as any ) // TODO: Not sure why this doesn't see it and needs to be casted to any?
172
+ . get ( rawRid )
163
173
. map ( ( data ) => {
164
174
res . send ( JSON . stringify ( data , null , 4 ) ) ;
165
175
} )
@@ -217,8 +227,6 @@ export const movexServer = <TDefinition extends MovexDefinition>(
217
227
// start the server
218
228
const port = process . env [ 'port' ] || 3333 ;
219
229
httpServer . listen ( port , ( ) => {
220
- const address = httpServer . address ( ) ;
221
-
222
230
// console.log(`[movex-server] v${pkgVersion} started at port ${port}.`);
223
231
224
232
// if (typeof address !== 'string') {
0 commit comments