-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
60 lines (46 loc) · 1.53 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
var express = require("express");
var app = express();
var path = require("path");
var dataServiceAuth = require(__dirname + "/final.js");
app.use(express.static('public'));
var HTTP_PORT = process.env.PORT || 8080;
function onHttpStart(){
console.log("Express http server listening on: " + HTTP_PORT);
}
app.get("/", function(req, res){
res.sendFile(path.join(__dirname, "/finalViews/home.html"));
});
app.get("/home", function(req, res){
res.sendFile(path.join(__dirname, "/finalViews/home.html"));
});
app.get("/register", function(req, res){
res.sendFile(path.join(__dirname, "/finalViews/register.html"));
});
app.post("/register", (req,res) => {
dataServiceAuth.registerUser(req.body)
.then(() => res.sendFile("registered successfully. <a href='/home'> Go Home </a>"))
.catch (res.sendFile("Error: email or password cannot be empty"))
});
app.get("/signIn", function(req, res){
res.sendFile(path.join(__dirname, "/finalViews/signIn.html"));
});
app.post("/signIn", (req,res) => {
dataServiceAuth.checkUser(req.body)
.then(user => {
res.send("Signed in successfully. <a href='/home'> Go Home </a> ");
})
.catch(err => {
res.send("Not Found")
})
});
app.use((req, res) => {
res.status(404).end('404 PAGE NOT FOUND');
});
dataServiceAuth.initialize()
.then(function(){
app.listen(HTTP_PORT, function(){
console.log("app listening on: " + HTTP_PORT)
});
}).catch(function(err){
console.log("unable to start server: " + err);
});