Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:res[content-length] only shows size less than 1 KB #273

Open
bryantamayo1 opened this issue Dec 27, 2022 · 2 comments
Open

:res[content-length] only shows size less than 1 KB #273

bryantamayo1 opened this issue Dec 27, 2022 · 2 comments

Comments

@bryantamayo1
Copy link

If one reponse has a size of body less than 1KB it's showed in console. On the contrary, it doesn't, only show a hyphen. I would know the size independently of amount.

@dougwilson
Copy link
Contributor

Hi @bryantamayo1 very sorry for your issue. Unfortunately your issue would likely be outside of morgan, as all the :res[content-length] token does is show the value of res.headers['content-length'], which it would appear is blank in some cases for you. You would likely need to address the cause of that in order to get morgan to display the size.

If you are sure the issue is actually in morgan, certainly we can help here, but would need more information, specifically exact code, details, and instructions on how to replicate your issue so we can troubleshoot it.

@bryantamayo1
Copy link
Author

This is my simple code:

import express from 'express';
import morgan from 'morgan';
const compression = require('compression');
const app = express();
const PORT = 3000;

app.use(compression());
app.use(morgan(':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] B :total-time ms ":referrer" ":user-agent"'));

app.use("/test", (req, res, next) => {
    const info = [
        {
            "_id": "637289c055a3b946fc1f3cac",
            "title": "tes-100",
            "createdAt": "2022-11-14T18:32:32.134Z"
        },
        {
            "_id": "637289c055a3b946fc1f3cac",
            "title": "tes-100",
            "createdAt": "2022-11-14T18:32:32.134Z"
        },
        {
            "_id": "637289c055a3b946fc1f3cac",
            "title": "tes-100",
            "createdAt": "2022-11-14T18:32:32.134Z"
        },
        {
            "_id": "63728bf15e87a2696b829109",
            "title": "tes-101",
            "createdAt": "2022-11-14T18:41:53.435Z"
        },
        {
            "_id": "63728c2129071c9eaa6498bd",
            "title": "tes-102",
            "createdAt": "2022-11-14T18:42:41.900Z"
        },
        {
            "_id": "637cf65933d5bb594fa14345",
            "title": "tes_6¿?'*^```+`][[[{|@#@~44",
            "description": "tes",
            "createdAt": "2022-11-22T16:18:33.780Z"
        },
        {
            "_id": "637d066ba5b00fdd965d8975",
            "title": "12212",
            "createdAt": "2022-11-22T17:27:07.224Z"
        },
        {
            "_id": "637ffd689df662c79d5b26e7",
            "title": "jueves-1",
            "createdAt": "2022-11-24T23:25:28.518Z"
        },
        {
            "_id": "637ffdd524f8b978c9ebdb7c",
            "title": "jueves-2",
            "createdAt": "2022-11-24T23:27:17.097Z"
        },
        {
            "_id": "637ffe8824f8b978c9ebdba5",
            "title": "jueves-3",
            "createdAt": "2022-11-24T23:30:16.222Z"
        },
        {
            "_id": "637fffaa4992428576a95fdf",
            "title": "jueves-4",
            "description": "descripción - 4",
            "createdAt": "2022-11-24T23:35:06.006Z"
        },
        {
            "_id": "638000979f91bc92350591d9",
            "title": "jueves-5",
            "description": "jueves-5-descripcion-jueves-5-descripcion-jueves-5-descripcion-jueves-5-descripcion-jueves-5-descripcion-jueves-5-descripcion-jueves-5-descripcion-jueves-5-descripcion-jueves-5-descripcion-jueves-5-descripcion-jueves-5-descripcion-jueves-5-descripcion-jueves-5-descripcion-jueves-5-descripcion-jueves-5-descripcion-",
            "createdAt": "2022-11-24T23:39:03.934Z"
        },
        {
            "_id": "63800397fce2f6e6ef63c977",
            "title": "jueves-6",
            "description": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
            "createdAt": "2022-11-24T23:51:51.761Z"
        },
        {
            "_id": "6380056739926dbf3682a727",
            "title": "jueves-7",
            "description": "555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555",
            "createdAt": "2022-11-24T23:59:35.021Z"
        },
        {
            "_id": "63800c0a2e5606728095a98e",
            "title": "b-project-1",
            "createdAt": "2022-11-25T00:27:54.810Z"
        },
        {
            "_id": "63810f8599dfd3c83c560d63",
            "title": "b-project-2",
            "createdAt": "2022-11-25T18:55:01.492Z"
        },
        {
            "_id": "6381207b78e673ce3e8e90da",
            "title": "b-project-3",
            "createdAt": "2022-11-25T20:07:23.193Z"
        },
        {
            "_id": "6384c37b51766f61bbfd9958",
            "title": "project-28-11-2022",
            "createdAt": "2022-11-28T14:19:39.554Z"
        },
        {
            "_id": "63ab2f3bb0fa5258eebf9803",
            "title": "project-27-12-2022",
            "createdAt": "2022-12-27T17:45:31.845Z"
        },
        {
            "_id": "63ab35d1dc3a80576d828b82",
            "title": "project-27-12-2022-v2",
            "createdAt": "2022-12-27T18:13:37.376Z"
        },
        {
            "_id": "63ab3fbd3747463d20479f72",
            "title": "project-27-12-2022-v3",
            "createdAt": "2022-12-27T18:55:57.905Z"
        }
    ];
    return res.json({
        status: "success",
        data: info
    });
});

app.listen(PORT, () => {
    console.log(`[server] is listening on ${PORT}`);
});

And these are my logs:

::1 - - [29/Dec/2022:13:46:29 +0000] "GET /test HTTP/1.1" 200 - B 10.345 ms "-" "PostmanRuntime/7.29.2"

Where is the amount of Bytes?

But if I comment the middleware:

// app.use(compression());

This works and show the amount of Bytes Ok:

::1 - - [29/Dec/2022:13:47:57 +0000] "GET /test HTTP/1.1" 200 3177 B 5.582 ms "-" "PostmanRuntime/7.29.2"

Perhaps is the mistake library compression?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants