This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
111 lines (83 loc) · 2.39 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
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
express = require('express');
var app = express();
var bodyParser = require('body-parser');
var mysql = require('mysql');
app.use(bodyParser.urlencoded({extended: false}));
var connection = mysql.createConnection({
host: 'localhost',
port: 3306,
user: 'root',
password: 'qwerty',
database: 'games_page'
});
connection.connect(function(err) {
if (err) {
console.error('mysql connection error');
console.error(err);
throw err;
}
});
app.get('/', function (req, res) {
res.sendfile( __dirname + '/front/index.html');
});
app.get('/form.css', function (req, res) {
res.sendfile( __dirname + '/front/form.css');
});
app.get('/form.js', function (req, res) {
res.sendfile( __dirname + '/front/form.js');
});
app.get('/intro', function (req, res) {
res.sendfile( __dirname + '/front/intro.html');
});
app.get('/index.css', function (req, res){
res.sendfile( __dirname + '/front/index.css');
});
app.get('/intro.js', function (req, res) {
res.sendfile( __dirname + '/front/intro.js');
});
app.get('/notice', function (req, res){
res.sendfile( __dirname + '/front/notice.html');
});
app.get('/notice.css', function (req, res){
res.sendfile( __dirname + '/front/notice.css');
});
app.get('/notice.js', function (req, res){
res.sendfile( __dirname + '/front/notice.js');
});
app.get('/jquery', function (req, res){
res.sendfile( __dirname + '/front/jquery-1.11.1.js');
});
app.get('/res/logo.png', function (req, res){
res.sendfile( __dirname + '/front/res/logo.png');
});
app.get('/res/login.png', function (req, res){
res.sendfile( __dirname + '/front/res/login.png');
});
app.get('/res/banner.png', function (req, res){
res.sendfile( __dirname + '/front/res/banner.png');
});
app.get('/jquery-ui.css', function (req, res){
re.sendfile( __dirname + '/font/jquery-ui.min.css');
});
app.get('/jquery-ui.js', function (req, res){
res.sendfile( __dirname + '/front/jquery-ui.min.js');
});
app.post('/login', function (req, res){
var user = {
id: req.body.id,
password: req.body.password
};
var query = connection.query('insert into user set ?',user,function (err, result){
if(err) {
console.log(err);
throw err;
}
console.log(query);
res.send(200,'success');
})
});
var server = app.listen(80, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});