Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 266307da authored by 65160014's avatar 65160014
Browse files

Initial commit

parent b6502efd
Branches
No related tags found
No related merge requests found
...@@ -5,7 +5,7 @@ const app = express(); ...@@ -5,7 +5,7 @@ const app = express();
const port = 3000; const port = 3000;
// การตั้งค่าการเชื่อมต่อฐานข้อมูล MySQL (ใช้ pool) // การตั้งค่าการเชื่อมต่อฐานข้อมูล MySQL (ใช้ pool)
const db = mysql.createConnection({ const db = mysql.createPool({
host: process.env.DB_HOST, host: process.env.DB_HOST,
port: process.env.DB_PORT, port: process.env.DB_PORT,
user: process.env.DB_USER, user: process.env.DB_USER,
...@@ -17,14 +17,14 @@ const db = mysql.createConnection({ ...@@ -17,14 +17,14 @@ const db = mysql.createConnection({
}); });
// Test the database connection to ensure everything is set up correctly // Test the database connection to ensure everything is set up correctly
db.connect(err => { db.getConnection((err, connection) => {
if (err) throw err; if (err) throw err;
console.log("Connected to the database."); console.log("Connected to the database.");
connection.release(); // Release the connection back to the pool
}); });
module.exports = { db }; module.exports = { db };
// การตั้งค่า Express session // การตั้งค่า Express session
app.use(session({ app.use(session({
secret: 'your_secret_key', secret: 'your_secret_key',
...@@ -55,8 +55,8 @@ app.get('/', (req, res) => { ...@@ -55,8 +55,8 @@ app.get('/', (req, res) => {
app.use('/auth', require('./routes/auth')); app.use('/auth', require('./routes/auth'));
app.use('/admin', require('./routes/admin')); app.use('/admin', require('./routes/admin'));
app.use('/customer', require('./routes/customer')); app.use('/customer', require('./routes/customer'));
// Starting the server // Starting the server
app.listen(port, () => { app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`); console.log(`Server is running on http://localhost:${port}`);
}); });
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment