UNPKG

@interopio/gateway-server

Version:
103 lines (80 loc) 2.78 kB
# io.Gateway Server [![npm version](https://img.shields.io/npm/v/@interopio/gateway-server.svg)](https://www.npmjs.com/package/@interopio/gateway-server) ## Overview The `@interopio/gateway-server` package is the web server used to run the gateway as a standalone server app accessible via WebSocket. ## Table of Contents - [Getting Started](#getting-started) - [Configure HTTPS](#configure-https) - [@glue42/gateway-ent Compatibility](#glue42gateway-ent-compatibility) ## Getting Started ```typescript import GatewayServer, {type Server} from '@interopio/gateway-server'; const server: Server = await GatewayServer({ port: 8385, gateway: { route: '/gw', access: 'authenticated' } }); await server.close(); ``` ## Configure HTTPS ```typescript import GatewayServer, {type Server} from '@interopio/gateway-server'; const server: Server = await GatewayServer({ port: 8443, ssl: { cert: "glue42.crt", ca: "intermediate.crt", key: "glue42.key" }, auth: { type: 'oauth2', // or 'basic' oauth2: { jwt: { issuer: 'https://auth.example.com', audience: 'https://api.example.com' } }, basic: { username: 'interopio', password: 'passwordo' } }, app: async ({handle}) => { handle( { request: {method: 'GET', path: '/api/metrics'}, options: {cors: true, authorize: {access: 'authenticated'}}, handler: async ({response}) => { response.setStatusCode({value: 200}); // OK await response.end(); } }, { request: {method: 'POST', path: '/api/metrics'}, options: {cors: true, authorize: {access: 'authenticated'}}, handler: async ({request, response}) => { response.statusCode({value: 202}); // Accepted await response.end(); try { const update = await request.json(); console.log(`${JSON.stringify(update)}`); } catch (e) { console.error('Error processing metrics:', e); } } }); }, }); await server.close(); ``` ## `@glue42/gateway-ent` Compatibility This package aims to provide compatibility with `@glue42/gateway-ent` proprietary package used in Glue42 Desktop (now io.Connect Desktop) ```javascript import * as gw from '@interopio/gateway-server/gateway-ent'; ``` ## Changelog See [changelog](./changelog.md) ## License [Interop.io Developer License Agreement](license.md)