-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
73 lines (56 loc) · 2.01 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
const express = require('express');
const bcrypt = require('bcrypt-nodejs');
const cors = require('cors');
const knex = require('knex');
const register = require('./controllers/register');
const signin = require('./controllers/signin');
const profile = require('./controllers/profile');
const image = require('./controllers/image');
// var whitelist = [
// 'https://immense-fjord-12656.herokuapp.com/imageurl',
// 'https://immense-fjord-12656.herokuapp.com/image',
// 'https://immense-fjord-12656.herokuapp.com/register',
// 'https://immense-fjord-12656.herokuapp.com/signin',
// 'https://kevins-facial-recognition-app.herokuapp.com',
// 'https://immense-fjord-12656.herokuapp.com/'
// ]
// var corsOptions = {
// origin: function (origin, callback) {
// if (whitelist.indexOf(origin) !== -1) {
// callback(null, true)
// } else {
// callback(new Error('Not allowed by CORS'))
// }
// }
// }
//process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
const db = knex({
client: 'pg',
connection: {
connectionString : process.env.DATABASE_URL,
rejectUnauthorized: false
// user : 'postgres',
// password : '',
// port: '5433',
//database : 'facial-recognition'
}
});
const app = express();
//Middleware that parses the JSON body into JS that we can read
app.use(express.json());
//Using cors
app.use(cors());
//app.options('*', cors());
app.get('/', (req, res) => { res.send('it is working') })
// Sign-In also includes a more advanced function/call
app.post('/signin', (req, res) => {signin.handleSignIn(db, bcrypt)})
// Register
app.post('/register', (req, res) => { register.handleRegister(req, res, db, bcrypt)})
//Getting the users homepage
app.get('/profile/:id', (req, res) => { profile.handleProfileGet(req, res, db)})
//Updating the image count
app.put('/image', (req, res) => {image.handleImage(req, res, db)})
app.post('/imageurl', (req, res) => { image.handleApiCall(req, res)})
app.listen(process.env.PORT || 3001, () => {
console.log(`app is running on port ${process.env.PORT}`);
})