Rob--W / cors-anywhere

CORS Anywhere is a NodeJS reverse proxy which adds CORS headers to the proxied request.
MIT License
8.57k stars 5.99k forks source link

Package break after webpack minification #424

Closed parliament718 closed 2 years ago

parliament718 commented 2 years ago

I have noticed that when I use "mode: production" in webpack (essentially minifying the code), cors-anywhere breaks and returns gibberish in the responses:

Screen Shot 2022-05-29 at 11 30 20 PM

The proxy code is:

import * as corsProxy from 'cors-anywhere';

const port = 8914;
const host = 'localhost';

corsProxy
   .createServer({ })
   .listen(port, host, () => {
      console.log('Running CORS Anywhere on ' + host + ':' + port);
   });

If I compile it with webpack build --config ./server.webpack.js with the following server.webpack.js, with mode: 'production' is just returns the gibberish above

const config = {
   target: 'node',
   entry: {
      'index': path.resolve(__dirname, 'src/index.ts')
   },
   output: {
      path: path.resolve(__dirname, './dist'),
      filename: '[name].js'
   },
   module: {
      rules: [
         {
            test: /\.ts$/,
            use: [{
               loader: 'ts-loader',
               options: {
                  configFile: 'tsconfig.json'
               }
            }],
            exclude: /node_modules/,
         },
         {
            test: /.node$/,
            loader: 'node-loader',
         }
      ]
   },
   plugins: [
   ],
   mode: 'production', <-- HERE
   resolve: {
      extensions: ['.js', '.ts']
   },
   devtool: false
};

module.exports = config;
Rob--W commented 2 years ago

That looks strange. I'm afraid that I don't have time to investigate this issue, and suggest to not use webpack for this lib and its dependency, or to not switch to production mode.