This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const getUsers$ = EffectFactory | |
| .matchPath('/') | |
| .matchType('GET') | |
| .use(req$ => req$.pipe( | |
| switchMap(Dao.getUsers), | |
| map(users => ({ body: users })), | |
| )); | |
| const postUser$ = EffectFactory | |
| .matchPath('/') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const effect$: Effect = (req$) => | |
| req$.pipe( | |
| // ... | |
| ); | |
| const middleware$: Middleware = (req$, res) => | |
| req$.pipe( | |
| // ... | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const authorize$: Middleware = (req$) => | |
| req$.pipe( | |
| switchMap(req => iif( | |
| () => !isAuthorized(req), | |
| throwError(new HttpError('Unauthorized', HttpStatus.UNAUTHORIZED)), | |
| of(req), | |
| )), | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { use, matchEvent } from '@marblejs/core'; | |
| import { WsEffect } from '@marblejs/websockets'; | |
| import { t, eventValidator$ } from '@marblejs/middleware-io'; | |
| export const sum$: WsEffect = event$ => | |
| event$.pipe( | |
| matchEvent('SUM') | |
| ); | |
| export const add$: WsEffect = (event$, ...args) => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { use, r } from '@marblejs/core'; | |
| const postUser$ = r.pipe( | |
| r.matchPath('/'), | |
| r.matchType('POST'), | |
| r.use(authorize$), | |
| r.useEffect(req$ => req$.pipe( | |
| use(postUserValidator$), | |
| map(req => req.body), | |
| mergeMap(createUser), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const server = createServer({ | |
| port: 1337, | |
| httpListener, | |
| dependencies: [ | |
| bindTo(WsServerToken)(webSocketListener().run), | |
| ], | |
| }); | |
| // ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const userSchema: t.type({ | |
| id: t.string, | |
| name: t.string, | |
| age: t.number, | |
| roles: t.array(t.union([ | |
| t.literal('ADMIN'), | |
| t.literal('GUEST'), | |
| ])), | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { bodyParser$, jsonParser } from '@marblejs/middleware-body'; | |
| bodyParser$({ | |
| parser: jsonParser, | |
| type: ['*/json', 'application/vnd.api+json'], | |
| }) | |
| // or | |
| import { bodyParser$, urlEncodedParser } from '@marblejs/middleware-body'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const httpsOptions: https.ServerOptions = { | |
| key: fs.readFileSync('key.pem'), | |
| cert: fs.readFileSync('cert.pem'), | |
| }; | |
| const listening$: HttpServerEffect = event$ => | |
| event$.pipe( | |
| matchEvent(ServerEvent.listening), | |
| map(event => event.payload), | |
| tap(({ port, host }) => console.log(`Running @ http://${host}:${port}/`)), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createServer, combineRoutes, httpListener, r } from '@marblejs/core'; | |
| import { logger$ } from '@marblejs/middleware-logger'; | |
| import { bodyParser$ } from '@marblejs/middleware-body'; | |
| import { map, mapTo } from 'rxjs/operators'; | |
| // USERS API definition | |
| const getUserList$ = r.pipe( | |
| r.matchPath('/'), | |
| r.matchType('GET'), |
OlderNewer