Skip to content

Commit

Permalink
feat: add index bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkaroid committed Apr 18, 2023
1 parent c87412b commit 789ed00
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import "dotenv/config";
import LustPress from "./LustPress";
import express from "express";
import { Request, Response, NextFunction } from "express";
import scrapeRoutes from "./router/endpoint";
import { slow, limiter } from "./utils/limit-options";
import { logger } from "./utils/logger";
import * as pkg from "../package.json";

const lust = new LustPress();
const app = express();


app.get("/", slow, limiter, async (req, res) => {
res.send({
success: true,
playground: "https://sinkaroid.github.io/lustpress",
endpoint: "https://github.com/sinkaroid/lustpress/blob/master/README.md#routing",
date: new Date().toLocaleString(),
rss: lust.currentProccess().rss,
heap: lust.currentProccess().heap,
server: await lust.getServer(),
version: `${pkg.version}`,
});
logger.info({
path: req.path,
method: req.method,
ip: req.ip,
useragent: req.get("User-Agent")
});
});

app.use(scrapeRoutes());
app.use((req: Request, res: Response, next: NextFunction) => {
res.status(404);
next(Error(`The page not found in path ${req.url} and method ${req.method}`));
logger.error({
path: req.url,
method: req.method,
ip: req.ip,
useragent: req.get("User-Agent")
});
});

app.use((error: any, res: Response) => {
res.status(500).json({
message: error.message,
stack: error.stack
});
});

app.listen(process.env.PORT || 3000, () => console.log(`${pkg.name} is running on port ${process.env.PORT || 3000}`));

0 comments on commit 789ed00

Please sign in to comment.