-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
117 lines (91 loc) · 3.12 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const express = require("express");
//set up express app
const app = express();
//redirect http to https
const secure = require("ssl-express-www");
//app.use(secure);
const env = require('dotenv').config();
const bodyParser = require('body-parser');
//initialize routes
const routes = require('./routes/api');
const jwt = require('jsonwebtoken');
const fetch = require("node-fetch");
const PORT = process.env.PORT || 3000;
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var path = require('path');
var indexRouter = require('./routes/api');
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(logger('dev'));
app.use(cookieParser());
app.use('/', indexRouter);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(routes);
app.use(express.static(__dirname));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
//listen for requests
app.listen(PORT, function(){
console.log("Server started at port 3000!");
})
app.use(function(req, res, next) {
res.status(404).sendFile(path.join(__dirname, "/public/404.html"));
});
// var users = [
// {
// username: 'ankitanshu',
// password: 'xyz123',
// name: 'Ankitanshu',
// email: '[email protected]'
// }, {
// username: 'anna',
// password: 'password123member',
// Name: 'Anna',
// email: '[email protected]'
// }
// ];
// var newUser = {
// username: '',
// password: '',
// name: '',
// email: ''
// }
// const accessTokenSecret = process.env.SECRET_KEY;
// app.post("/users/login", function(req,res){
// // Read username and password from request body
// const username = req.body.user.UserName;
// const password = req.body.user.password;
// // Filter user from the users array by username and password
// const user = users.find(u => { return u.username === username && u.password === password });
// if (user) {
// // Generate an access token
// const accessToken = jwt.sign({ username: user.username, name: user.name }, accessTokenSecret);
// res.json({
// accessToken
// });
// } else {
// res.send('Username or password incorrect');
// }
// });
// app.post("/users", function(req,res){
// // Read name, email, username and password from request body
// const username = req.body.user.UserName;
// const password = req.body.user.password;
// const email = req.body.user.Email;
// const name = req.body.user.Name;
// newUser.username=username;
// newUser.password=password;
// newUser.email=email;
// newUser.name=name;
// users.push(newUser);
// // Filter user from the users array by username and password
// const user = users.find(u => { return u.username === username && u.password === password });
// if (user) {
// // Generate an access token
// const accessToken = jwt.sign({ username: user.username, name: user.name }, accessTokenSecret);
// } else {
// res.send('Username or password incorrect');
// }
// });