-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainScript.js
More file actions
76 lines (66 loc) · 2.11 KB
/
MainScript.js
File metadata and controls
76 lines (66 loc) · 2.11 KB
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
var express = require('express');
var bodyParser = require('body-parser');
var helper = require(__dirname+'/HelperFunctions.js');
var dbHandler = require(__dirname+'/DatabaseHandler.js');
var app = express();
var httpPort = 8085;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
for (let i = 0; i < process.argv.length;i++) {
//console.log(process.argv[i]);
if (process.argv[i].indexOf('-port=') == 0) {
httpPort = process.argv[i].substring(6);
//console.log(httpPort);
}
}
if (httpPort == "") {
console.log('Port is missing!');
process.exit();
}
app.listen(httpPort,function(err,res){
if(err) throw err;
console.log('HTTP Server is running at '+httpPort);
});
app.get('/',function(httpReq,httpRes){
httpRes.sendFile(__dirname+'/HomePage.html');
});
app.post('/Contribute',function(httpReq,httpRes){
var strWord = httpReq.body.Word;
strWord = strWord.toUpperCase();
var strDesctription = httpReq.body.Description;
if(helper.IsValidWord(strWord) == true){
if(helper.IsValidDescription(strDesctription) == true){
var JSONToInsert = {
word:httpReq.body.Word,
description:httpReq.body.Description,
startLetter:'',
endLetter:'',
length:0
};
if(dbHandler.Insert(JSONToInsert) == true){
httpRes.redirect('/WordAddSuccess');
}
else{
httpRes.redirect('/WordAddFail');
}
}
else{
httpres.redirect('/InvalidDescription');
}
}
else{
httpRes.redirect('/InvalidWord');
}
});
app.get('/InvalidWord',function(httpReq,httpRes){
httpRes.sendFile(__dirname+'/InvalidWord.html');
});
app.get('/InvalidDescription',function(httpReq,httpRes){
httpRes.sendFile(__dirname+'/InvalidDescription.html');
});
app.get('/WordAddSuccess',function(httpReq,httpRes){
httpRes.sendFile(__dirname+'/WordAddSuccess.html');
});
app.get('/WordAddFail',function(httpReq,httpRes){
httpRes.sendFile(__dirname+'/WordAddFail.html');
});