question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I’m having problems with charset, naturally the codes in .aspx need (and I don’t know ecxacly why) the ISO-8859-1. Prints someting like this: *capacita��o de *

        browserSync: {
            geral: {
                bsFiles: {
                    src: [
                        '**/*.html',
                        '**/*.css',
                        '**/*.min.js',
                        '**/*.aspx',
                        '**/*.master',
                        '**/*.ashx'
                    ]
                },
                options: {
                    watchTask: true,
                    startPath: "/default.aspx",
                    proxy: config.host + ':' + config.port,
                    notify: false,
                    open: false
                }
            }
        },

With aspx, ours programmers insert the content of news, in web.config I found this. http://prntscr.com/7eitat

But if i change the value of charset here, nothing more works.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:5
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jwvcommented, Apr 21, 2022

I’m trying to use the code above but I’m getting the following error:

node:_http_server:279
    throw new ERR_HTTP_INVALID_STATUS_CODE(originalStatusCode);
    ^

RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: undefined

Any idea what could be missing in my case?

Fixed version. Tested node v17.9.0.

var browserSync = require("browser-sync").create();
var iconv = require("iconv-lite");

browserSync.init({
  watch: false,
  proxy: {
    target: "http://mydomain.local",
    proxyRes: [
      (proxyRes, req, res) => {
        if (
          proxyRes.headers &&
          proxyRes.headers["content-type"] &&
          proxyRes.headers["content-type"].match("text/html")
        ) {
          const _end = res.end;
          const _writeHead = res.writeHead;
          let buffer = Buffer.from("");

          proxyRes.on("data", chunk => {
            buffer = Buffer.concat([buffer, chunk]);
          });

          res.write = () => {};
          res.writeHead = (...args) => {
            _writeHead.apply(res, args);
          };

          res.end = () => {
            _end.call(res, iconv.decode(buffer, "iso-8859-1"));
          };
        }
      },
      function(res) {
        if (
          res.headers &&
          res.headers["content-type"] &&
          res.headers["content-type"].match("text/html")
        )
        res.headers["content-type"] = "text/html; charset=utf-8";
      }
    ]
  }
});
1reaction
skotnicznycommented, May 18, 2018

Based on @kokarn’s and @youngzhaosignifyd’s examples and with the help of iconv-lite, plus using proxyRes option I am successfully using this script:

proxyRes: [
  (proxyRes, req, res) => {
    if( proxyRes.headers && proxyRes.headers["content-type"] &&
        proxyRes.headers["content-type"].match("text/html") ) {
            
      const _end = res.end
      const _writeHead = res.writeHead
      let writeHeadArgs
      let buffer = new Buffer("")

      proxyRes.on("data", (chunk) => {
        buffer = Buffer.concat([buffer, chunk])
      })

      res.write = () => {};
      res.writeHead = (...args) => {writeHeadArgs = args}

      res.end = () => {
        _writeHead.apply(res, writeHeadArgs)
        _end.call(res, iconv.decode(buffer, "iso-8859-2"))
      }
    }
  }
]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Solving character encoding problems - jAlbum Wiki
Problem. Computers store text as a sequence of numbers where each character has a unique number according to an agreed upon "character encoding...
Read more >
The character set problem - Hostpoint Support Center
This error is the easiest to correct. The data is stored and output with a consistently defined charset, but the charset being used...
Read more >
How to fix character encoding issue in html? - Stack Overflow
1 Answer 1 · On Notepad++ select Encoding -> ISO-8859-15 and save the file. · Use <meta http-equiv="Content-Type" content="text/html; charset=ISO- ...
Read more >
Charset (character encoding) problem: text is displayed ...
Non-Latin characters in commit messages or file contents are displayed as squares or unknown characters.
Read more >
Fix Character Encoding on Your Website - Larry Kagan
A step-by-step guide to troubleshooting and repairing character encoding problems in your website.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found