-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
72 lines (61 loc) · 1.51 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
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const knex = require('knex')({
client: 'pg',
connection: {
host : '127.0.0.1',
user : 'mohit3',
password : '',
database : 'frb'
}
});
const bcrypt = require('bcrypt');
const saltRounds = 10;
const signin = require('./controllers/signin');
const register = require('./controllers/register');
const profile = require('./controllers/profile');
const image = require('./controllers/image');
const app = express();
app.use(bodyParser.json());
app.use(cors());
/* const database = {
users: [
{
id: 1,
name: 'mohit',
email: '[email protected]',
password: 'password123',
entries: 0,
joined: new Date()
},
{
id: 2,
name: 'hersh',
email: '[email protected]',
password: 'password456',
entries: 0,
joined: new Date()
}
],
login: [
{
id: 1,
hash: '',
email: '[email protected]'
}
]
} */
app.get('/', (req, res) => {
knex.select().from('users').then(data => {
res.send(data);
});
});
app.post('/signin', (req, res) => { signin.handleSignin(req, res, knex, bcrypt) });
app.post('/register', (req, res) => {register.handleRegister(req, res, knex, bcrypt, saltRounds)});
app.get('/profile/:id', (req, res) => {profile.handleProfile(req, res, knex)});
app.put('/image', (req, res) => {image.handleImage(req, res, knex)});
app.post('/imageurl', (req, res) => {image.callClarifaiApi(req, res)});
app.listen(3000, () => {
console.log("Started server");
});