forked from WheelMap/WheelMap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
73 lines (62 loc) · 1.91 KB
/
app.js
File metadata and controls
73 lines (62 loc) · 1.91 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
const mysql = require('mysql2');
const db = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '0000',
database: 'wm'
});
const express = require('express');
const cors = require('cors');
const app = express();
const port = 3000;
app.use(express.json());
app.get('/search', (req, res) => {
const searchQuery = req.query.searchQuery;
res.json({ result: searchQuery });
});
db.connect((err) => {
if (err) {
console.error('MySQL 연결 오류:', err);
throw err;
}
console.log('MySQL 데이터베이스에 연결되었습니다.');
db.query(`
CREATE TABLE IF NOT EXISTS user_info (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
profile_picture_url VARCHAR(255)
)
`, (err, result) => {
if (err) {
console.error('테이블 생성 중 오류 발생:', err);
db.end(); // 에러 발생 시 연결 종료
return;
}
console.log('user_info 테이블이 생성되었습니다.');
const userInfo = {
name: '카카오톡에서 받은 이름',
email: '카카오톡에서 받은 이메일',
profile_picture_url: '프로필 사진 링크 URL'
};
app.get('/search/:name',function(request, response){
//var body = request.body;
console.log(request.params.name);
//input으로 받은 menu 값 출력 확인
});
db.query('INSERT INTO user_info SET ?', userInfo, (err, result) => {
if (err) {
console.error('데이터 저장 중 오류 발생:', err);
db.end(); // 에러 발생 시 연결 종료
return;
}
console.log('데이터가 성공적으로 저장되었습니다.');
db.end((err) => {
if (err) {
console.error('MySQL 연결 종료 오류:', err);
}
console.log('MySQL 데이터베이스 연결이 종료되었습니다.');
});
});
});
});