I have this project where I need to insert the content of a website to my local SQL Server. This website has a webhook feature where I can connect using a valid URL.
I have to use this webhook to track the changes that are made on this site.
So, I'm using Netlify to create a valid URL and then creating a function to re-direct the content received from the webhook to my local server, where I already configured ports, firewalls and IPs Fowardings.
But when I deploy de function to Netlify, trigger the webhook, and check the log of the function, it says that it couldn't connect to my server.
12:10:43 PM: 4935afd1 ERROR Unhandled Promise Rejection
{"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"ConnectionError:
Failed to connect to <my_external_ip>:<my_port> in
15000ms"
Here is the code that i deploy in Netlify:
const connStr = "Server=<my_external_ip>,<my_port>;Database=<my_db>;User Id=<my_usr>;Password=<my_pass>;trustServerCertificate=true;";
const sql = require("mssql");
exports.handler = async (event, context) => {
try {
const body = JSON.parse(event.body);
// Inicio do Banco
teste = sql.connect(connStr)
.then(conn => insertTable(connStr, body))
.catch(err => console.log("erro! " + err));
function insertTable(conn, body){
const col1 = body.col1
const col2 = body.col2
const col3 = body.col3
new sql.Request().query(`INSERT INTO <TABLE_NAME> (COL1, COL2, COL3) VALUES ('${col1}', '${col2}', ${col3})`, (err, result) => {
console.dir(result)
})
}
// Fim do Banco
console.log("Submitted!");
return {
statusCode: 204,
};
} catch (err) {
return { statusCode: 500, body: err.toString() };
}
};
I think my server's configuration is ok because I can remotely connect through SSMS to my database.