-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
92 lines (70 loc) · 2.42 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
85
86
87
88
89
90
91
92
import express, { json } from 'express';
import bcrypt from 'bcrypt-nodejs';
import cors from 'cors';
import knex from 'knex';
import { handleRegister } from './controllers/register.js';
import { SignInhandle } from './controllers/signin.js';
import { ProfileHandle } from './controllers/profile.js';
import { ImageHandle, ImageURL } from './controllers/image.mjs';
import clarifai from 'clarifai';
const db = knex({
client: 'pg',
connection: {
connectionString : process.env.DATABASE_URL,
ssl: { rejectUnauthorized: false },
host: process.env.DATABASE_HOST,
port : 5432,
user : process.env.DATABASE_USER,
password : process.env.DATABASE_PW,
database : process.env.DATABASE_DB
}
});
// Custom middleware to check input length
const validateInputLength = (maxAllowedLength) => (req, res, next) => {
// Check the length of the request body or query parameters, depending on your usage
const requestData = req.body || req.query;
for (const key in requestData) {
if (requestData[key].length > maxAllowedLength) {
return res.status(400).json({ error: `Input data for '${key}' exceeds the allowed length.` });
}
}
next(); // Proceed to the next middleware
};
// const db = knex({
// client: 'pg',
// connection: {
// host: 'dpg-clrafsae9h4c73atnd20-a',
// port : 5432,
// user : 'facedetectbackendx22_user',
// password : 'Ay3N8TbWMD80rhnorOmo0cs0l72tsZl1',
// database : 'facedetectbackendx22'
// }
// });
db.select('*').from('users').then(data => {
console.log(data);
});
const app = express();
app.use(json());
app.use(cors())
app.get('/',(req,res) => {
res.send(database.user);
})
app.post('/signin', validateInputLength(20),(req,res) => {SignInhandle(req,res,db,bcrypt)})
app.post("/register", validateInputLength(20),(req,res) => { handleRegister(req,res,db,bcrypt)})
app.get('/profile/:id',(req,res) => { ProfileHandle(req,res,db)})
app.put('/image',(req,res) => { ImageHandle(req,res,db)})
app.post('/imageurl',(req,res) => { ImageURL(req,res)})
// let found = false;
// database.user.forEach(i => {
// if(i.id===id) {
// found = true;
// i.entries++;
// return res.json(i.entries);
// }
// })
// if(!found){
// res.status(404).json('no such user');
// }
app.listen(3000, ()=> {
console.log('app is runing')
})