-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
54 lines (41 loc) · 1.43 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
// Express.js for server-side routing
const express = require("express");
const PORT = process.env.PORT;
// bcrypt for hashing passwords
const bcrypt = require("bcrypt-nodejs");
const cors = require("cors");
const knex = require("knex");
const register = require("./controllers/register");
const signin = require("./controllers/sign-in");
const profile = require("./controllers/profile");
const image = require("./controllers/image");
// SPECIFY YOUR DATABASE CONNECTION. Modify this line to suit to your own needs.
const db = knex({
client: "pg",
connection: {
connectionString: process.env.DATABASE_URL,
ssl: true
}
});
// https://protected-scrubland-83638.herokuapp.com/
const app = express();
// allow cross origin resource sharing
app.use(cors());
app.use(express.json());
//profile/:userId --> GET Request --> {user}
app.get("/", (req, res) => {
res.send("App is working!");
});
//signin --> POST Request --> Success/Fail
app.post("/signin", signin.handleSignIn(db, bcrypt));
//register --> POST Request --> {user}
app.post("/register", register.handleRegister(db, bcrypt));
//profile/:userId --> GET Request --> {user}
app.get("/profile/:id", profile.handleProfileGet(db));
//image --> PUT --> user (with updated count)
app.put("/image", image.handleImagePut(db));
//API call to Clarifai
app.post("/imageurl", image.handleApiCall());
app.listen(PORT || 3000, () => {
console.log(`Server Successfully Started on Port ${PORT}`);
});