Browse Source

fix logging

master
Lio 3 months ago
parent
commit
155f3dd278
3 changed files with 5 additions and 7 deletions
  1. +1
    -0
      .gitignore
  2. +0
    -5
      index.ts
  3. +4
    -2
      middleware/log.ts

+ 1
- 0
.gitignore View File

@@ -1,2 +1,3 @@
node_modules/
config.ts
build/

+ 0
- 5
index.ts View File

@@ -1,12 +1,10 @@
import Armpits from "@sniff/armpits";
import express from "express";
import { allowedNodeEnvironmentFlags } from "process";
import config from "./config";
import middleware from "./middleware/index";
import { CreateLink } from "./utils/database";
import { ErrorResponse } from "./utils/generators";
const app = express();

app.use(express.json());
app.use(middleware.database);
app.use(middleware.log);
@@ -16,7 +14,6 @@ app.get("/", async (req, res) => {

app.get("/all", async (req, res) => {
let links = [];

req.db.list({ include_docs: true }).then((body) => {
body.rows.forEach((row) => {
delete row.doc._id;
@@ -30,7 +27,6 @@ app.get("/all", async (req, res) => {
app.post("/", middleware.lock, async (req, res) => {
try {
let { target, code } = req.body;

if (!target)
return res
.status(400)
@@ -39,7 +35,6 @@ app.post("/", middleware.lock, async (req, res) => {
let Link = await CreateLink({ target, code });
return res.send(Link);
} catch (error) {
// console.error(error);
res.send({
success: false,
error: ErrorResponse(error.message),


+ 4
- 2
middleware/log.ts View File

@@ -1,6 +1,8 @@
import Armpits from "@sniff/armpits";
export default function log(req, res, next) {
delete req.body.token;
Armpits.info(`${req.method} Request to ${req.path} with data:`, req.body);
Armpits.info(`${req.method} Request to ${req.path} with data:`, {
code: req.body.code,
target: req.body.target,
});
next();
}

Loading…
Cancel
Save