-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
108 lines (99 loc) · 3.3 KB
/
server.js
File metadata and controls
108 lines (99 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
// const express = require('express');
// const bodyParser = require('body-parser');
// const mysql = require('mysql');
// import fetch from 'node-fetch'; // Import the 'node-fetch' package
//
// const app = express();
// const port = 3000;
//
// // Create MySQL connection
// const db = mysql.createConnection({
// host: 'localhost',
// user: 'root',
// password: '1234',
// database: 'dengue_project_db'
// });
//
// // Connect to MySQL
// db.connect((err) => {
// if (err) {
// console.error('Error connecting to MySQL database:', err.message);
// // Gracefully handle the error, e.g., exit the application or log the error
// process.exit(1);
// }
// console.log('Connected to MySQL database');
// });
//
// // Middleware
// app.use(bodyParser.json());
//
// // Example endpoint to fetch weather data for a location
// app.get('/predictDengueWarning', async (req, res) => {
// const location = req.query.location;
// try {
// const weatherData = await fetchWeatherData(location);
// const preprocessedData = preprocessWeatherData(weatherData);
// const prediction = mlModel.predict(preprocessedData);
// res.json({ prediction });
// } catch (error) {
// console.error('Error predicting dengue warning:', error.message);
// res.status(500).json({ error: 'Failed to predict dengue warning' });
// }
// });
//
// // Function to fetch weather data from an external API (e.g., OpenWeather)
// async function fetchWeatherData(location) {
// const apiKey = '9e425371311cb9bc2598ffefe2c5b53a';
// const apiUrl = `https://api.openweathermap.org/data/2.5/weather?q=${location}&appid=${apiKey}&units=metric`;
// const response = await fetch(apiUrl);
// const data = await response.json();
// return data;
// }
//
// // Function to preprocess weather data (implement as needed)
// function preprocessWeatherData(weatherData) {
// // Implement preprocessing logic here if necessary
// return weatherData;
// }
//
// // Load your machine learning model (mlModel) here (replace with actual implementation)
//
// app.listen(port, () => {
// console.log(`Server is running on port ${port}`);
// });
const express = require('express');
const bodyParser = require('body-parser');
const predictionRoutes = require('./routes/predictionRoutes'); // Import the prediction routes
const dengueRoutes = require('./routes/dengueRoutes');
const weatherRoutes = require('./routes/weatherRoutes');
const authRoutes = require('./routes/authRoutes');
const app = express();
const port = 3001; // Changed from 3000 to 3001
const mysql = require('mysql2');
// Create MySQL connection
const mysqlConnection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '1234',
database: 'dengue_project_db'
});
// Connect to MySQL
mysqlConnection.connect((err) => {
if (err) {
console.error('Error connecting to MySQL database:', err.message);
process.exit(1);
}
console.log('Connected to MySQL database');
});
// Middleware
app.use(bodyParser.json());
// Use the routes
app.use('/prediction', predictionRoutes);
app.use('/dengue', dengueRoutes);
app.use('/weather', weatherRoutes);
app.use('/auth', authRoutes);
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
*/