timeout errors when trying to configure azure mysql to railway backend

has anyone experienced time out errors in railway when fetching things from a azure database? Currently in development it works fine in fetching from the database in mysqlWorkbench, so i do know the connection is working However, when i put it in a railway server it is unable to access to any data of the database at all in azure right now. Maybe it is due to how i initialized my connection? Sorry, im super new, so any help would be appreciated! some relevant code trying to make connection to the azure SQL: <-code below-> const mysql = require('mysql2'); const fs = require('fs'); const dotenv = require('dotenv'); dotenv.config(); // Configuration object for your SQL Server connection const configurations= { host: process.env.HOST, database: process.env.DATABASE, user: process.env.CLIENT, password: process.env.PASSWORD, port: process.env.PORT, ssl:{ca:fs.readFileSync(process.ev.URL)}, /* waitForConnections: true, connectTimeout: 60000, queueLimit: 0, */ }; const db = mysql.createConnection(configurations).promise(); module.exports = db;
No description
31 Replies
Percy
Percy7mo ago
Project ID: N/A
TheFriendinYou
TheFriendinYou7mo ago
N/A
Brody
Brody7mo ago
please enclose all code in triple backticks
TheFriendinYou
TheFriendinYou7mo ago
Gotcha I’m not sure but maybe the environment variables I defined in railway may have caused a problem,as I defined for example for process.env.host as HOST=(myhostname) in the variables
Brody
Brody7mo ago
Triple backticks
Jack
Jack7mo ago
Misspelt “env” with “ev”
Brody
Brody7mo ago
I saw but I'm more confused at why they're trying to read a file from a url environment variable
Jack
Jack7mo ago
Yeah…
TheFriendinYou
TheFriendinYou7mo ago
Oh yeah I’m new to azure so let me clarify
Jack
Jack7mo ago
I’d suggest either putting the file in the repo or using axios to get the file from the URL so it’ll download it
TheFriendinYou
TheFriendinYou7mo ago
I think it was one of the authentication methods azure used
Jack
Jack7mo ago
Yeah, certificates
TheFriendinYou
TheFriendinYou7mo ago
Oh yeah that’s a typo in my part when sending this code, I didn’t want to send the Actual file path I wonder if it was a conflict with having MySQL workbench online at the same time but I doubt it
Jack
Jack7mo ago
Should’ve just set it to “PATH” or misc, looks like an additional error on our ends There’s no firewall settings on any of those services, right?
TheFriendinYou
TheFriendinYou7mo ago
Shoot there is I only enabled my IP I think
Brody
Brody7mo ago
host: process.env.HOST,
database: process.env.DATABASE,
user: process.env.CLIENT,
password: process.env.PASSWORD,
port: process.env.PORT,
host: process.env.HOST,
database: process.env.DATABASE,
user: process.env.CLIENT,
password: process.env.PASSWORD,
port: process.env.PORT,
can you please give all these correct variable names? HOST -> AZURE_HOST DATABASE -> AZURE_DATABASE and so on, i believe once you have your variables named correctly it could work, or at the very least, rule out possible conflicting variable names
TheFriendinYou
TheFriendinYou7mo ago
The only one I think could conflict is the port name
Brody
Brody7mo ago
exactly
TheFriendinYou
TheFriendinYou7mo ago
I used 3306
Brody
Brody7mo ago
please name your variables properly and get back to us
TheFriendinYou
TheFriendinYou7mo ago
Ok so I established connection to azure sql and I successfully was able to get access to the data in my server So basically the railway server is successfully connected but now the problem I think lies in post requests now
Brody
Brody7mo ago
what's the issue with post requests?
TheFriendinYou
TheFriendinYou7mo ago
I’ll send my code once I get back but I am getting null when making them and getting no response as well as a blank screen. There’s probably something wrong in my frontend and post request I deployed my frontend on netlify
Brody
Brody7mo ago
are you making sure to make your requests with https
TheFriendinYou
TheFriendinYou7mo ago
Yes I’m making a cookies request in the code do you think the it may cause conflict?
Brody
Brody7mo ago
there is some funky stuff with cross origin cookies, id recommend watching some YouTube videos on the subject
TheFriendinYou
TheFriendinYou7mo ago
Alright gotcha Here’s what it I’m doing whenever I’m trying to authenticate users,
const cookieOptions = {
httpOnly: false,
path: '/',
secure: true,
}


const token = jwt.sign(user, secretKey, { expiresIn: '2h' });

res.cookie('token', token, cookieOptions)
const cookieOptions = {
httpOnly: false,
path: '/',
secure: true,
}


const token = jwt.sign(user, secretKey, { expiresIn: '2h' });

res.cookie('token', token, cookieOptions)
Brody
Brody7mo ago
I've never done jwt auth in any context, YouTube would be a much better help there, especially since this isn't super railway related
TheFriendinYou
TheFriendinYou7mo ago
ok thanks, just one more question since i was able solve all the issues except for one this isnt railway related but I just wanted to know if youve had experience with uploading images to database. I was working with multer and was wondering how to display the images in a production setting(since it dosent have a file path in production that the images are saved onto). Im wondering if theres a possible way to avoid this
Brody
Brody7mo ago
well first you dont want to put images in a database, you want to use a volume https://docs.railway.app/guides/volumes and then heres a multer example that uses railways volumes https://github.com/brody192/multer-file-uploads
TheFriendinYou
TheFriendinYou7mo ago
ok thank you!