42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import http from "http";
|
|
import express from "express";
|
|
import cors from "cors";
|
|
import { Server } from "colyseus";
|
|
import { monitor } from "@colyseus/monitor";
|
|
// import socialRoutes from "@colyseus/social/express"
|
|
|
|
import { GeneralRoom } from "./rooms/GeneralRoom";
|
|
import {MongooseDriver} from "colyseus/lib/matchmaker/drivers/MongooseDriver";
|
|
import {initData} from "./common/GConfig";
|
|
|
|
|
|
const port = Number(process.env.PORT || 2567);
|
|
const app = express()
|
|
|
|
|
|
app.use(cors());
|
|
app.use(express.json())
|
|
initData();
|
|
const server = http.createServer(app);
|
|
const gameServer = new Server({
|
|
server,
|
|
driver: new MongooseDriver('mongodb://192.168.100.24/card-development'),
|
|
});
|
|
|
|
// register your room handlers
|
|
gameServer.define('general_room', GeneralRoom);
|
|
|
|
/**
|
|
* Register @colyseus/social routes
|
|
*
|
|
* - uncomment if you want to use default authentication (https://docs.colyseus.io/server/authentication/)
|
|
* - also uncomment the import statement
|
|
*/
|
|
// app.use("/", socialRoutes);
|
|
|
|
// register colyseus monitor AFTER registering your room handlers
|
|
app.use("/colyseus", monitor());
|
|
|
|
gameServer.listen(port);
|
|
console.log(`Listening on ws://localhost:${ port }`)
|