How to use the @marblejs/core.httpListener function in @marblejs/core

To help you get started, we’ve selected a few @marblejs/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marblejs / marble / packages / @integration / src / messaging / client.ts View on Github external
)),
      map(body => ({ body })),
    );
  }),
);

const listening$: HttpServerEffect = event$ =>
  event$.pipe(
    matchEvent(ServerEvent.listening),
    map(event => event.payload),
    tap(({ port, host }) => console.log(`Server running @ http://${host}:${port}/ 🚀`)),
  );

export const server = createServer({
  port,
  httpListener: httpListener({
    middlewares: [logger$()],
    effects: [test$, fib$],
  }),
  dependencies: [
    bindTo(ClientToken)(client),
  ],
  event$: (...args) => merge(
    listening$(...args),
  ),
});

if (process.env.NODE_ENV !== 'test') {
  server();
}
github marblejs / marble / packages / @integration / src / websockets / http.server.ts View on Github external
mapToServer({
      path: '/api/:version/ws',
      server: ask(WsServerToken),
    }),
  );

const listening$: HttpServerEffect = event$ =>
  event$.pipe(
    matchEvent(ServerEvent.listening),
    map(event => event.payload),
    tap(({ port, host }) => console.log(`Server running @ http://${host}:${port}/ 🚀`)),
  );

export const server = createServer({
  port: 1337,
  httpListener: httpListener({
    middlewares: [logger$()],
    effects: [root$],
  }),
  dependencies: [
    bindEagerlyTo(WsServerToken)(websocketsServer),
  ],
  event$: (...args) => merge(
    listening$(...args),
    upgrade$(...args),
  ),
});

if (process.env.NODE_ENV !== 'test') {
  server();
}
github marblejs / marble / packages / @integration / src / api.integration.spec.ts View on Github external
const file$ = EffectFactory
  .matchPath('/static/:dir')
  .matchType('GET')
  .use(req$ => req$
    .pipe(
      map(req => req.params!.dir as string),
      switchMap(readFile(STATIC_PATH)),
      map(body => ({ body }))
    ));

const user$ = combineRoutes('/user', [getUserList$, getUserSingle$, postUser$]);

const api$ = combineRoutes('/api/:version', [root$, file$, error$, user$]);

const app = httpListener({
  middlewares: [bodyParser$],
  effects: [api$],
});

describe('API integration', () => {
  it('returns 404 when route not found: /', async () =>
    request(app)
      .post('/')
      .expect(404));

  it('returns status 200: /api/v1', async () =>
    request(app)
      .get('/api/v1')
      .expect(200, '"root"'));

  it('returns error response: /api/v1/error', async () =>
github marblejs / marble / packages / middleware-multipart / src / specs / multipart.middleware.spec.ts View on Github external
)));

const filesystemMultipart$ = r.pipe(
  r.matchPath('/filesystem'),
  r.matchType('POST'),
  r.useEffect(req$ => req$.pipe(
    use(multipart$({
      stream: streamFileTo(TMP_PATH),
    })),
    map(req => ({ body: {
      files: req.files,
      fields: req.body,
    }}))
  )));

const app = httpListener({
  effects: [memoryMultipart$, memoryWithOptionsMultipart$, filesystemMultipart$],
}).run(createContext());

afterEach(() => {
  if (fs.existsSync(TMP_PATH)) { fs.rmdirSync(TMP_PATH); }
});

describe('multipart$', () => {
  test('parses multipart/form-data request with additional fields and stores it in-memory', async () => {
    const data = Buffer.from('test_buffer_1');

    return request(app)
      .post('/memory')
      .field('field_1', 'test_1')
      .field('field_2', 'test_2')
      .attach('data_field', data)
github marblejs / marble / packages / serverless / src / +awsLambda / spec / awsLambda.spec.ts View on Github external
expect(() => createLambda({
      type: 'unknown' as any,
      httpListener: httpListener({ effects: [] }),
    })).toThrowError('Invalid type specified.');
  });
github marblejs / marble / packages / serverless / src / +awsLambda / spec / awsLambda.spec-setup.ts View on Github external
mapTo(({
      status: 200,
      headers: {
        'transfer-encoding': 'chunked',
      },
      body: new Readable({
        read(): void {
          this.push(JSON.stringify({ key: 'value' }));
          this.push(null);
        }
      }),
    }))
  ))
);

const app = httpListener({
  middlewares: [
    bodyParser$(),
    awsApiGatewayMiddleware$(),
  ],
  effects: [
    effect$,
    chunkedTransferEncodingEffect$,
  ],
});

export const createHandler = () => createLambda({
  httpListener: app,
  type: ProxyType.AWS,
  proxyOptions: {
    logger: () => void 0,
  },
github marblejs / example / src / app.ts View on Github external
import { bodyParser$ } from '@marblejs/middleware-body';
import { logger$ } from './api/common/middlewares/logger.middleware';
import { cors$ } from './api/common/middlewares/cors.middleware';
import { api$ } from './api';

const middlewares = [
  cors$,
  logger$,
  bodyParser$(),
];

const effects = [
  api$,
];

export const app = httpListener({ middlewares, effects });