-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
37 lines (31 loc) · 887 Bytes
/
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
const express = require("express");
const app = express();
const db = require("./database");
const HTTP_PORT = 3003
app.listen(HTTP_PORT, () => {
console.log(`Server running on port ${HTTP_PORT}`);
});
app.get("/", (req, res) => {
res.json({"status": 200, "message": "OK"});
// res.send("Hello World!");
});
app.get('/api/communitys', (req, res) => {
const query = "select * from community";
db.all(query, (err, rows) =>{
if (err) {
console.error(err.message);
res.status(400).json({
"error": err.message,
"data": []
});
return;
} else{
res.header('Access-Control-Allow-Origin', 'http://localhost:3000')
.status(200)
.json({
"message": "success",
"data": rows
});
}
});
});