Skip to content

Commit

Permalink
feat: socket implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo2392 committed Nov 15, 2024
1 parent 66d9881 commit 097c247
Show file tree
Hide file tree
Showing 7 changed files with 409 additions and 91 deletions.
220 changes: 216 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"express-rate-limit": "^7.4.1",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.7.1",
"mongoose-paginate-v2": "^1.8.5"
"mongoose-paginate-v2": "^1.8.5",
"socket.io": "^4.8.1"
}
}
1 change: 1 addition & 0 deletions src/controllers/track.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import express from "express";
import trackService from "../services/track.service";
import { ERRORS_M, RESPONSE_M } from "../dto/error.dto";
import { StartTrackDto } from "../dto/track.dto";
import io from "socket.io";

export interface Query {
page: number;
Expand Down
27 changes: 24 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ import ProjectRoutes from "./routes/projects.routes";
import TrackRoutes from "./routes/track.routes";
import { CommonRoutes } from "./routes/common.routes";
import { errorHandler } from "./middlewares/error.middleware";
import mongoService from "./services/mongo.service";
import http from "http";
import SocketService from "./services/socket.service";

const app = express();

const server = http.createServer(app);

new SocketService(server);

const limiter = rateLimit({
windowMs: 10 * 60 * 1000, // 15 minutes
limit: 100,
Expand All @@ -22,7 +29,7 @@ const limiter = rateLimit({
});

app.set("trust proxy", 1);
app.use(limiter);
// app.use(limiter);

app.use(cors());
app.use(bodyparser.json());
Expand All @@ -39,12 +46,26 @@ routes.push(new TrackRoutes(app));
app.get("/", (req, res) => {
res.json({ message: "API CRONOWORK V1" });
});
app.get("/healthcheck", async (_req, res, _next) => {
try {
const mongoose = mongoService.getMongoose();
const healthcheck = {
uptime: process.uptime(),
status: "OK",
timestamp: Date.now(),
mongo: mongoose.connection.readyState === 1 ? "OK" : "unknow",
};
res.status(200).json(healthcheck);
} catch (err) {
res.status(503).json({ err });
}
});

app.use(errorHandler);

app.listen(port, () => {
server.listen(port, () => {
routes.map((el) => {
console.log(`Route ${el.getName()}`);
});
console.log(`Server on port: ${port}`);
console.log(`listening on *:${port}`);
});
Loading

0 comments on commit 097c247

Please sign in to comment.