-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
76 lines (55 loc) · 1.98 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
API design
/signin --> POST = success/fail
/register --> POST = user
/profile/:userId --> GET = user
/image --> PUT = user updated
*/
const express = require('express');
const bcrypt = require('bcrypt-nodejs');
const cors = require('cors');
const knex = require('knex')
const register = require('./controllers/register')
const singin = require('./controllers/singin')
const profile = require('./controllers/profile')
const image = require('./controllers/image')
const auth = require('./controllers/authorization')
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
/* prod */
const _DATABASE_URL = process.env.DATABASE_URL;
const _PORT = process.env.PORT;
const _SLL_ENABLED = true;
/* dev */
/*
const _DATABASE_URL = "postgresql://postgres:426430@localhost/face_recognition";
const _PORT = 3000;
const _SLL_ENABLED = false;
*/
console.log(process.env.POSTGRES_HOST);
const db = knex({
client: 'pg',
connection: {
host: process.env.POSTGRES_HOST,
user: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
database: process.env.POSTGRES_DB
//connectionString : _DATABASE_URL,
//ssl: _SLL_ENABLED
}
});
//db.select('*').from('users').then(data => console.log(data));
const app = express();
console.log('running app service...');
app.use(express.urlencoded({extended: false}));
app.use(express.json());
app.use(cors());
app.get('/', (req, res) => res.send('It´s working'));
app.post('/signin', singin.signinAuthentication(db, bcrypt))
app.post('/register', (req, res) => { register.handleRegister(req, res, db, bcrypt) });
app.get('/profile/:id', auth.requireAuth, (req, res) => { profile.handleProfile(req, res, db) } );
app.post('/profile/:id', auth.requireAuth, (req, res) => { profile.handleProfileUpdate(req, res, db) } );
app.put('/image', auth.requireAuth, (req, res) => { image.handleImage(req, res, db) } )
app.post('/imageUrl', auth.requireAuth, (req, res) => { image.handleApiCall(req, res) } )
app.listen(_PORT, () => {
console.log('app running at -> ' + _PORT)
});