Skip to content

Commit

Permalink
bump version again
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCactusBlue committed Feb 23, 2024
1 parent 7f6492f commit 6d87c6f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
11 changes: 3 additions & 8 deletions apps/typescript/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ const hss = new HyperschemaServer({
system: hs,
root: hs.MainService,
transports: [
new SocketIOTransport(
new socketIO.Server(app.server, {
cors: { origin: '*' },
}),
),
new SocketIOTransport({
port: 3100,
}),
],
writers: [
new TypeScriptWriter(path.join(__dirname, '../../client/src/hs-client.ts')),
Expand All @@ -34,9 +32,6 @@ const hss = new HyperschemaServer({
console.log('generating hyperschema...');
await hss.start({ generate: true });
console.log('generated hyperschema!');
app.listen({ port: 3100 }, () => {
console.log('listening on port 3100');
});
})().then(() => {
console.log('server started');
});
2 changes: 1 addition & 1 deletion packages/typescript/hyperschema-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"types": "dist/index.d.ts",
"packageManager": "[email protected]",
"license": "MIT",
"version": "0.0.10",
"version": "0.0.11",
"devDependencies": {
"@types/node": "^20.7.0",
"@types/ws": "^8.5.10",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export function processError(err: unknown) {

export interface AbstractTransportEngine {
mount(service: HyperRPCService<any>): void;
run(): Promise<void>;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fastify from 'fastify';
import * as socketIO from 'socket.io';

import { HyperRPCService, MetaObject } from '..';
Expand Down Expand Up @@ -29,10 +30,34 @@ function setupServiceEvents(socket: socketIO.Socket, service: HyperRPCService) {
});
}

interface SocketIOTransportOptions {
io?: socketIO.Server;
port?: number;
meta?: any;
}

export class SocketIOTransport implements AbstractTransportEngine {
io: socketIO.Server;
constructor(io: socketIO.Server) {
this.io = io;
run: () => Promise<void>;

constructor(options: SocketIOTransportOptions) {
if (options.io) {
this.io = options.io;
this.run = async () => {};
} else {
const app = fastify();
app.get('/', async () => {
return options.meta ?? { hello: 'world' };
});

this.io = new socketIO.Server(app.server, {
cors: { origin: '*' },
});

this.run = async () => {
await app.listen({ port: options.port ?? 3510 });
};
}
}

mount(service: HyperRPCService): void {
Expand Down
2 changes: 2 additions & 0 deletions packages/typescript/hyperschema-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ export class HyperschemaServer {
if (options.generate) {
await Promise.all(this.writers.map((w) => w.write(this.system)));
}

await Promise.all(this.transports.map((t) => t.run()));
}
}

0 comments on commit 6d87c6f

Please sign in to comment.