title: Create Proxy in NestJS
body: <p>I created a proxy with the nestjs.</p>
  
  <p>All requisitions pass normally. Except for POST requests.</p>
  
  <p>Look at my code:</p>
  
  <pre><code>import { IncomingMessage } from 'http';
  import { HttpUtils } from './../utils/http.utils';
  import { Controller, Param, Req, Res, All } from '@nestjs/common';
  import { Config } from './../system/config';
  import { ServerResponse } from 'http';
  import * as http from 'http';
  import { CouchDB, Log } from 'system';
  import { UsuarioModel } from 'model';
  
  @Controller('__api-proxy')
  export class ApiProxyController {
  
      @All('*')
      root(@Param() param, @Req() c_req: IncomingMessage, @Res() c_res: ServerResponse): any {
  
          // habilito o cors
          HttpUtils.enableCors(c_req, c_res);
  
          const urlDetail = HttpUtils.getUrlDetail(Config.getConfig().endpoints.webapi);
  
          // modifico para o hostname em que eu estou fazendo o proxy
          c_req.headers.host = urlDetail.hostname;
  
          // faço o proxy
          var proxy = http.request({
              hostname: urlDetail.hostname,
              port: urlDetail.port,
              method: c_req.method,
              headers: c_req.headers,
              path: '/' + param[0],
          }, (res) =&gt; {
              res.pause();
              res.headers.Server = `Sync Server ${Config.getConfig().package.version}`;
  
              if (Config.getConfig().endpoints.log) {
                  Log.print('[ api ] [' + c_req.connection.remoteAddress + ']     : ' + c_req.method + ' ' + res.statusCode + ' ' + c_req.url);
              }
  
              c_res.writeHead(res.statusCode, res.headers);
              res.pipe(c_res, {end: true});
              res.resume();
          });
  
          c_req.pipe(proxy, {end: true});
      }
  }
  </code></pre>
  
  <blockquote>
    <p>NodeJS error</p>
  </blockquote>
  
  <pre><code>Error: socket hang up
      at createHangUpError (_http_client.js:331:15)
      at Socket.socketOnEnd (_http_client.js:423:23)
      at emitNone (events.js:111:20)
      at Socket.emit (events.js:208:7)
      at endReadableNT (_stream_readable.js:1056:12)
      at _combinedTickCallback (internal/process/next_tick.js:138:11)
      at process._tickDomainCallback (internal/process/next_tick.js:218:9)
  </code></pre>
  
  <p>Before it worked normally, after I put the proxy under NestJS only GET and OPTIONS requests work. Can you help me?</p>