-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
38 lines (35 loc) · 1 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
const express = require("express");
const app = express();
const cors = require("cors");
app.use(cors());
const bodyParse = require("body-parser");
app.use(bodyParse.urlencoded({ extended: false }));
app.use(bodyParse.json());
const mysql = require("mysql");
const connection = mysql.createConnection({
//服务器连接配置 07.18
});
// console.log(connection);
// 查询;
app.get("/api/find", (req, res, next) => {
const sql =
"select * from weibo.weibo where retweet_pictures!='无' order by RAND() limit 1;"; //user为表名
connection.query(sql, (err, results) => {
console.log(results);
if (err) {
return res.json({
code: 1,
message: "连接错误",
});
}
res.json({
code: 200,
data: results,
});
});
});
app.get("/find", function(req, res) {});
//启动服务,端口3001
app.listen(3001, () => {
console.log("服务启动成功:" + `http://localhost:3001/`);
});