-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
67 lines (50 loc) · 1.75 KB
/
server.js
File metadata and controls
67 lines (50 loc) · 1.75 KB
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
//modules:
const express = require('express');
const bcrypt = require('bcrypt');
const cors = require('cors')
const {ClarifaiStub, grpc} = require("clarifai-nodejs-grpc");
//controllers:
const register = require('./controllers/register');
const signin = require('./controllers/signin');
const image = require('./controllers/image');
const profile = require('./controllers/profile')
////// injecting Environment Variables
const PORT = process.env.PORT || 3000;
const KEY = process.env.KEY;
const DB_PASSWORD = process.env.DB_PASSWORD;
const DATABASE_URL = process.env.DATABASE_URL;
//initialise
const app = express();
const knex = require('knex')({
client: 'pg',
connection: {
host : 'dpg-cf8noco2i3mmd0llo4l0-a',
port : 5432,
user : 'nisal',
password : DB_PASSWORD,
database : 'facedetectdb'
}
});
////middleware////
app.use(express.json())
app.use(cors())
//////////////////
app.get('/', (req, res) => {
res.send('it is working!')
})
app.post('/signin', (req, res) => signin.hangleSignIn(req, res, knex, bcrypt))
app.post('/register', (req, res) => register.handleRegister( req, res, knex, bcrypt)) //dependency inject the node modules as params
app.get('/profile/:id',(req,res) => profile.handleProfile(req, res, knex))
app.put('/image', (req,res) => image.hangleImage(req, res, knex, ClarifaiStub, grpc, KEY))
app.listen(PORT, ()=> {
console.log(`listening on port ${PORT}`);
//in terminal: PORT=3000 node server.js
//OR PORT=3000 npm start
})
/*
/--> res == this is working
/signin --> POST = success/fail //why post? whenever you send pw you dont wanna send in query string, you want to send password in the body via https
/register --> POST = user
/profile/:userId --> GET = user
/image --> PUT --> user
*/