0.3.0 • Published 6 years ago
@gsox/server v0.3.0
gsox-server
express webosocket and webhook middleware
Installation
npm i @gsox/server
Usage
import { applyMiddleware } from "@gsox/server"
// schema types
const inject = [Alert, Message]
const app = express();
// other endpoints
app.use('/', controller);
// apply gsox middleware
server = applyMiddleware(app, { host, port, inject })
server.listen(() => console.log('listening...'))
Options
endpoint route config and shared schema
import types from "./schema"
{
host: "localhost",
port: 3000,
routes: {
graphql: "/graphql",
webhook: "/webhook"
},
inject: [...Object.values(types)]
}
Schema Injection
inject class, instance, or string graphql type definition
const inject: {new ()}[] //constructor functions
| {}[] //objects
| string[] =
[
Notification, // class with
Message, // schema
new Alert(), // decorators
//or typedef
`message {
type: String
}`
]
Endpoints
Webhook
http://localhost:3000/webhook
publishes request body to client subscribers
POST
{
"Alert": {
id: 99,
type: "CRITICAL",
data: "CODE: 123"
}
}
Websocket
ws://localhost:3000/graphql
subscribe directly using graphql
subscription {
Alert {
id
type
data
}
}
0.3.0
6 years ago
0.3.0-alpha.6e5cde3d
6 years ago
0.3.0-alpha.c3b63b18
6 years ago
0.2.2
6 years ago
0.2.0
6 years ago
0.1.18
6 years ago
0.1.17
6 years ago
0.1.16
6 years ago
0.1.15
6 years ago
0.1.14
6 years ago
0.1.12
6 years ago
0.1.11
6 years ago
0.1.10
6 years ago
0.1.8
6 years ago
0.1.7
6 years ago
0.1.6
6 years ago
0.1.5
6 years ago
0.1.4
6 years ago
0.1.3
6 years ago
0.1.0
6 years ago