-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
61 lines (58 loc) · 1.9 KB
/
server.js
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
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const fs = require('fs');
const mysql = require('mysql');
const app = express();
const port = process.env.PORT || 5000;
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
const data = fs.readFileSync('./database.json');
const conf = JSON.parse(data)
const connection = mysql.createConnection({
host: conf.host,
user: conf.user,
password: conf.password,
port: conf.port,
database: conf.database
});
connection.connect();
app.get('/api/Library', (req,res)=>{
connection.query('SELECT * FROM Library', function(err,rows,fields){
res.header("Access-Control-Allow-Origin", "*");
res.send(rows)
})
})
app.get('/api/electricChair', (req,res)=>{
connection.query('SELECT * FROM Electric_WC_CS',function(err,rows,fields){
res.header("Access-Control-Allow-Origin", "*");
res.send(rows)
})
})
app.get('/api/electricChair/:data', (req,res)=>{
console.log(req.params.data)
connection.query('SELECT * FROM Electric_WC_CS WHERE 시설명=?',req.params.data, function(err,rows,fields){
res.header("Access-Control-Allow-Origin", "*");
res.send(rows)
})
})
app.get('/api/SWF', (req,res)=>{
connection.query('SELECT * FROM SWF',function(err,rows,fields){
res.header("Access-Control-Allow-Origin", "*");
res.send(rows)
})
})
app.get('/api/Tourism', (req,res)=>{
connection.query('SELECT * FROM Tourism',function(err,rows,fields){
res.header("Access-Control-Allow-Origin", "*");
res.send(rows)
})
})
// app.get('/api', (req,res)=>{
// connection.query('SELECT * FROM Library', function(err,rows,fields){
// res.header("Access-Control-Allow-Origin", "*");
// res.send(rows)
// })
// })
app.listen(port, ()=> console.log("서버 작동"))