mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-24 10:23:28 +00:00
Listen for websockets
This commit is contained in:
@ -16,6 +16,9 @@ import { CommentsController } from "./CommentsController";
|
||||
import { LikesController } from "./LikesController";
|
||||
import { SurveyController } from "./SurveyController";
|
||||
import { SettingsController } from "./SettingsController";
|
||||
import { Request } from "express";
|
||||
import * as ws from 'ws';
|
||||
import { UserWS } from "./UserWebSocketController";
|
||||
|
||||
/**
|
||||
* Controllers routes
|
||||
@ -25,7 +28,8 @@ import { SettingsController } from "./SettingsController";
|
||||
|
||||
export enum RouteType {
|
||||
POST, // Default
|
||||
GET
|
||||
GET,
|
||||
WS, // Special: WebSockets
|
||||
}
|
||||
|
||||
export interface Route {
|
||||
@ -33,10 +37,16 @@ export interface Route {
|
||||
path: string,
|
||||
cb: (req : RequestHandler) => Promise<void> | void,
|
||||
needLogin ?: boolean, // Default = true
|
||||
|
||||
// Specific for websockets
|
||||
wsCallback ?: (req: Request, ws: ws) => Promise<void> | void
|
||||
}
|
||||
|
||||
export const Routes : Route[] = [
|
||||
|
||||
// Main user websocket
|
||||
{type: RouteType.WS, path: "/ws", cb: () => {throw Error()}, wsCallback: UserWS },
|
||||
|
||||
// Welcome controller
|
||||
{type: RouteType.GET, path: "/", cb: WelcomeController.HomeMessage, needLogin: false},
|
||||
|
||||
|
11
src/controllers/UserWebSocketController.ts
Normal file
11
src/controllers/UserWebSocketController.ts
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* User websocket controller
|
||||
*
|
||||
* @author Pierre Hubert
|
||||
*/
|
||||
import * as ws from 'ws';
|
||||
import { Request } from 'express';
|
||||
|
||||
export async function UserWS(req: Request, ws: ws) {
|
||||
|
||||
}
|
Reference in New Issue
Block a user