-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
84 lines (66 loc) · 1.71 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
76
77
78
79
80
81
82
83
84
const express = require('express');
const body_parser = require('body-parser');
const bcrypt = require('bcrypt-nodejs');
const cors = require('cors');
const app = express();
const knex = require('knex');
const register = require('./controllers/register');
const signin = require('./controllers/signin');
const profile = require('./controllers/profile');
const image = require('./controllers/image');
const db = knex({
client: 'pg',
connection: {
host : '127.0.0.1',
user : 'postgres',
password : 'andrei98',
database : 'smart_brain'
}
});
app.use(cors());
app.use(body_parser.json());
const database={
users:[
{
id: '123',
name: 'Andrei',
email:'[email protected]',
password: 'pizza',
entries: 0,
joined:new Date()
},
{
id: '124',
name: 'Sally',
email:'[email protected]',
password: 'cookies',
entries: 0,
joined:new Date()
},
],
login:[
{
id:'987',
hasj:'',
email:'[email protected]'
}
]
}
app.get('/',(req, res)=>{
res.json('it is working');
})
app.post('/signin',(req, res)=>{signin.handleSignin(req,res,db,bcrypt)});
app.post('/register',(req,res)=>{register.handleRegister(req,res,db,bcrypt)});
app.put('/image',(req,res)=>{image.handleImage(req,res,db,bcrypt)});
app.post('/imageurl',(req,res)=>{image.handleApi(req,res)})
app.get('/profile/:id',(req,res)=>{profile.getProfile(req,res,db) });
app.listen(process.env.PORT ||3001, ()=>{
console.log(`App is running on port ${process.env.PORT}`);
})
/*
/ --> this is running
/signin --> POST = success/fail
/register --> POST = user
/profile/:id --> GET = user
/image --> PUT = updated user
*/