이찬

프론트와 연결

Showing 1 changed file with 35 additions and 35 deletions
1 -const fs = require('fs'); 1 +const port = process.env.PORT || 5000;
2 - 2 +const http = require('http');
3 const express = require('express'); 3 const express = require('express');
4 - 4 +const path = require('path');
5 -const bodyParser = require('body-parser'); 5 +const fs = require('fs'); // 파일 읽기, 쓰기 등 을 할 수 있는 모듈
6 -
7 const app = express(); 6 const app = express();
8 -
9 -const port = process.env.PORT || 5000;
10 -
11 -app.use(bodyParser.json());
12 -
13 -app.use(bodyParser.urlencoded({ extended: true }));
14 -
15 -
16 -
17 const data = fs.readFileSync('./database.json'); 7 const data = fs.readFileSync('./database.json');
18 -
19 const conf = JSON.parse(data); 8 const conf = JSON.parse(data);
20 -
21 const mysql = require('mysql'); 9 const mysql = require('mysql');
22 10
23 - 11 +app.use('/js', express.static(__dirname + '/js'));
12 +app.use('/css', express.static(__dirname + '/css'));
13 +app.use('/html', express.static(__dirname + '/html'));
14 +app.use('/img', express.static(__dirname + '/img'));
24 15
25 const connection = mysql.createConnection({ 16 const connection = mysql.createConnection({
26 17
...@@ -38,24 +29,33 @@ const connection = mysql.createConnection({ ...@@ -38,24 +29,33 @@ const connection = mysql.createConnection({
38 29
39 connection.connect(); 30 connection.connect();
40 31
41 - 32 +let DBdata = [];
42 - 33 +
43 -app.get('/api/visiter', (req, res) => { 34 +app.get('/', (req, res)=>{
44 - 35 + fs.readFile(path.join(__dirname,'html', 'index.html'), (err, data)=>{
36 + res.writeHead(200,{'Content-Type':'text/html'});
37 + res.end(data);
38 + })
39 +})
40 +app.get('/detail.html', (req, res)=>{
41 + fs.readFile(path.join(__dirname,'html', 'detail.html'), (err, data)=>{
42 + res.writeHead(200,{'Content-Type':'text/html'});
43 + res.end(data);
44 + })
45 +})
46 +
47 +app.get('/statistics.html', (req, res)=>{
48 + /*
45 connection.query( 49 connection.query(
46 - 50 + 'SELECT * FROM visiter',
47 - 'SELECT * FROM visiter',
48 -
49 (err, rows, fields) => { 51 (err, rows, fields) => {
50 - 52 + DBdata.push(rows);
51 - res.send(rows);
52 -
53 } 53 }
54 - 54 + )*/
55 - ) 55 + fs.readFile(path.join(__dirname,'html', 'statistics.html'), (err, data)=>{
56 - 56 + res.writeHead(200,{'Content-Type':'text/html'});
57 -}); 57 + res.end(data);
58 - 58 + })
59 - 59 +})
60 - 60 +
61 -app.listen(port, () => console.log(`Listening on port ${port}`)); 61 +app.listen(port, () => console.log(`Listening on port ${port}`));
...\ No newline at end of file ...\ No newline at end of file
......