-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
41 lines (34 loc) · 1.61 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
const express = require('express');
const cors = require('cors'); //allows connection with frontend (security reasons)
const knex = require('knex'); //SQL query builder (for connection with database)
const bcrypt = require('bcrypt-nodejs'); //to encrypt the password
const signin = require('./controllers/signin.js');
const register = require('./controllers/register.js');
const profile = require('./controllers/profile.js');
const image = require('./controllers/image.js');
const db = knex({
client: 'pg',
connection: {
connectionString: process.env.DATABASE_URL,
ssl: true
}
});
const app = express(); //creates server
app.use(express.json()); //parses body of request into json (otherwise when trying to read body we'll get an error)
app.use(cors()); //allows connection between frontend and backend
app.get('/', (req, res) => res.send("this 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.get('/profile/:id', (req, res) => profile.getProfile(req, res, db));
app.put('/image', (req, res) => image.handleImage(req, res, db));
app.post('/imageurl', (req, res) => image.handleApiCall(req, res));
app.listen(process.env.PORT || 3000, () => {
console.log(`app is running on port ${process.env.PORT}`);
});
/*
/ --> res = this is working (root route)
/signin --> POST = success/fail (it's a POST request in order to send the password safely in the body
/register --> POST = user
/profile/:userId --> GET = user
/image --> PUT = user (updates the number of images sent and the rank of that user)
*/