forked from akhilpandey95/bucket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.js
72 lines (62 loc) · 2.11 KB
/
web.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
var http = require('http'),
React =require('react'),
express = require('express'),
fs = require('fs'),
bcrypt = require('bcrypt'),
errorPage = fs.readFileSync("./404.html"),
cookieParser = require('cookie-parser'),
bodyParser = require('body-parser');
var port = process.env.PORT || 5000,
app = express(),
r = express.Router();
require('node-jsx').install();
app.use(express.static('assets'));
app.set('title', "Bucket Sharing");
app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
r.get('/', function(req, res) {
var data = fs.readFileSync("index.html", "utf-8");
res.send(data.toString());
});
r.get('/about', function(req, res) {
var data = fs.readFileSync("views/about.html", "utf-8");
res.send(data.toString());
});
r.get('/signup', function(req, res) {
var data = fs.readFileSync("views/signup.html", "utf-8");
res.send(data.toString());
});
r.post('/controller/login', function(req, res) {
var username = req.body.email;
var password = req.body.password;
var hash = bcrypt.compareSync(password, salt);
res.send(html);
});
r.post('/controller/signup', function(req, res) {
var username = req.body.username;
var email = req.body.email;
var pwd = req.body.password;
var confirm_pwd = req.body.password_confirm;
res.send(html);
});
r.get('*', function(req, res) {
var match = 'views/' + req.params[0]+ ".html";
fs.exists(match, function(exists) {
if(exists) {
fs.readFile(match, function(err, d) {
if(err)
res.end(errorPage.toString(), 'utf-8');
else
res.end(d, 'utf-8');
});
}
else {
res.end(errorPage.toString(), 'utf-8');
}
});
});
app.use('/', r);
http.createServer(app).listen(port, function() {
console.log("Listening on port 5000");
})