Express server not receiving webhook requests from TradingView

I have set up an Express server to handle webhook requests from TradingView, but the requests don’t seem to be reaching my server. Below is my server code and the steps I’ve taken to debug the issue. Despite configuring everything according to the documentation, the server logs do not show any incoming requests when an alert is triggered in TradingView.

Environment Variables (.env file):

PORT="8081"
DATABASE_USERNAME="root"
DATABASE_PASSWORD="rootpassword"
DATABASE_HOST="localhost"
DATABASE_PORT=3306
DATABASE_NAME="testtest"

Server Code:

import express from "express";
import Knex from "knex";
import bodyParser from "body-parser";
import axios from "axios";
import dotenv from 'dotenv';
import cors from 'cors';
import { SHA3 } from 'sha3';

const validSide = ["buy", "sell"];
const validPosition = ["long", "short"];

function hash(text) {
  const hasher = new SHA3(512);
  hasher.update(text);
  return hasher.digest('hex');
}

dotenv.config();

const app = express();
app.use(bodyParser.json());
app.use(cors());

const knex = Knex({
  client: 'mysql2',
  connection: {
    host: process.env.DATABASE_HOST,
    user: process.env.DATABASE_USERNAME,
    password: process.env.DATABASE_PASSWORD,
    database: process.env.DATABASE_NAME,
    port: process.env.DATABASE_PORT
  }
});

app.use((req, res, next) => {
  console.log('Request Method:', req.method);
  console.log('Request URL:', req.url);
  console.log('Request Headers:', req.headers);
  if (req.method === 'POST' || req.method === 'PUT') {
    console.log('Request Body:', req.body);
  }
  next();
});

app.get('/proxy', (req, res) => {
  res.send('Trade Proxy');
});

app.post('/proxy/response', async (req, res) => {
  const body = req.body;
  console.log('Received webhook:', body);

  if (!body.symbol || !body.side || !validSide.includes(body.side) || !body.position || !validPosition.includes(body.position) || !body.strategy || !body.hash || !body.close) {
    return res.status(400).json({
      success: false,
      message: '400 REQUEST ERROR',
      data: null
    });
  }

  try {
    const [strategy] = await knex('strategy_entity')
      .select("*")
      .where({ uuid: body.strategy });

    if (!strategy || strategy.hash !== body.hash) {
      return res.status(404).json({
        success: false,
        message: "Not FOUND STRATEGY",
        data: null
      });
    }

    const rows = await knex('server_entity')
      .select("*")
      .where({
        strategy_uuid: body.strategy,
        status: true
      });

    for (const entity of rows) {
      try {
        const serverURL = Buffer.from(entity.server, 'base64').toString('utf8');

        const requestData = {
          symbol: body.symbol,
          strategy: entity.uuid,
          side: body.side,
          position: body.position,
          close: body.close
        };

        const response = await axios.post(serverURL, requestData, {
          headers: { 'Content-Type': 'application/json' }
        });

        console.log(`Response from ${serverURL}: ${response.status}`);
      } catch (error) {
        console.log(`Error sending POST request: ${error.message}`);
      }
    }

    return res.status(200).json({
      success: true,
      message: null,
      data: null
    });
  } catch (err) {
    console.log(err);
    return res.status(500).json({
      success: false,
      message: 'Database Query Error',
      data: null
    });
  }
});

const port = process.env.PORT || 3000;
app.listen(port, () => {
  console.log("nn");

  console.log("┌───────────────────────────────────────────────────┐");
  console.log("│                      Express                      │");
  console.log(`│               http://127.0.0.1:${port}               │`);
  console.log(`│       (bound on host 0.0.0.0 and port ${port})       │`);
  console.log("│                                                   │");
  console.log("└───────────────────────────────────────────────────┘");
});

Steps I’ve Taken to Debug:
Verified Server is Running: Confirmed that the server is running and accessible via http://localhost:8081/proxy.
Checked Webhook URL: Set the webhook URL in TradingView to http://my-server-ip:8081/proxy/response.
Checked Firewall and Network Settings: Ensured that the server can receive external requests by checking firewall and network settings.
Log Requests: Added middleware to log all incoming requests. However, no requests are logged when the TradingView alert is triggered.

When I tested the webhook functionality by registering it with TradingView using Discord’s webhook feature, it worked perfectly. However, when sending the webhook to my server, even with middleware set up for logging, I noticed that no requests were received.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật