-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsever.js
71 lines (55 loc) · 1.76 KB
/
sever.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
process.env.NODE_TLS_REJECT_UNAUTHORIZED='0'
const { Client } = require('pg');
var express = require('express');
var bodyParser = require('body-parser');
const jwt = require('jsonwebtoken');
const client = new Client({
connectionString: "postgres://jnllxhyrgazyey:3dc84e638e10c1ca9e7baf88149b0bfd979acbe4f0ea7dd2b02fddf6402b0273@ec2-54-226-18-238.compute-1.amazonaws.com:5432/d2m6n3gvn9u6u4",
ssl: true,
});
client.connect();
var myapp = express();
const path = require('path');
const router = express.Router();
myapp.use(function(req, res, next){
req.headers['content-type'] = "application/json";
next();
});
myapp.get('/', function(req, res) {
res.sendFile( __dirname);
res.sendFile(path.join(__dirname + '/school/home/index.html'));
});
myapp.use(express.static(__dirname + '/school/home'));
myapp.use(bodyParser.urlencoded({ extended: true }));
myapp.use(bodyParser.json());
myapp.post('/auth/signup', function (req, res) {
client.connect();
var datae = {};
var school = {};
var name = req.body.name;
var age = req.body.age;
var classes = req.body.class;
var sex = req.body.sex;
var scores = req.body.scores;
var maId = 3;
const text = "INSERT INTO School(id,name,age,class,sex,scores) VALUES('NULL', '"+ name +"', '"+ age +"', '"+ classes +"', '"+ sex +"', '"+ scores +"') RETURNING id;";
client.query(text, (err, resp) => {
if (err){
datae['status'] = 404;
datae['error'] = "Error: Problem occur when signing up...";
res.send(datae);
}else{
datae['status'] = 200;
datae = {};
name = first_name;
age = age;
classes = classes ;
sex = sex;
scores = scores;
datae['data'] = "now you are register....";
res.send(datae);
}
});
});
const portr = process.env.PORT || 3000;
myapp.listen(portr);