-
Notifications
You must be signed in to change notification settings - Fork 15
/
server.js
41 lines (33 loc) · 1.03 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
var path = require("path");
var express = require("express");
var db = require("./database/db.js");
var bodyParser = require("body-parser");
var handle = require("./server/requestHandler.js");
var app = express();
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, "/public")));
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
res.header(
"Access-Control-Allow-Methods",
"OPTIONS, DELETE, POST, GET, UPDATE"
);
next();
});
//WEB APP ENDPOINTS//
app.get("/", function(req, res) {
res.send("Hello, humans!");
});
app.get("/api/users/:id", handle.usersGet);
app.post("/api/users/", handle.userPost);
app.delete("/api/users/urls", handle.urlRemove);
app.post("/api/users/notes/", handle.userAddNotes);
app.delete("/api/users/notes", handle.noteRemove);
var port = process.env.PORT || 3003;
app.listen(port, () => {
console.log(`server listening at ${port}`);
});