-
Notifications
You must be signed in to change notification settings - Fork 1
/
NSF.js
88 lines (69 loc) · 2.42 KB
/
NSF.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
var express = require("express");
var http = require("http");
var path = require("path");
var exphbs = require('express-handlebars');
var support =require("./model/model.js"); // Get model function
var supportdb = require("./model/dbconnection.js"); // Get model function
const expressSession = require('express-session'); // Get the session handling middleware for express
const session = require("express-session");
const { nextTick } = require("process");
const { captureRejectionSymbol } = require("events");
// Construct the actual express object
var app= express();
// Set up handlebars
var handlebars = exphbs.create({defaultLayout: 'main'});
app.engine('.handlebars', handlebars.engine);
app.set('view engine', 'handlebars');
app.use(express.static('views'));
// Set its properties
app.use(expressSession(
{
resave: false,
saveUninitialized: false,
secret: "abcd1234EFGH", // Secret key to sign session ID
cookie: {maxAge: 600000} // Session exprires in 600,000 ms (10 minutes)
}
));
// When home page requested initially load Stationery's first page into session
app.get("/", function(request, response)
{
if (!request.session.awardlist) //If no productlist list in session
{
var result;
supportdb.getAwards(function(result)
{
request.session.awardlist =result;
//console.log(request.session.awardlist); -- its printing
//console.log(result);
response.render("home");
});
// request.session.pdlist = support.getpdlist(); // Load aproductlist and store now, session starts
}
else
{
response.render("home");
}
});
// try
app.get("/home", function(request,response)
{
response.render("home",{awardselect:request.session.awardlist});
});
//try
// When Product selection requested , diplay it with session
app.get("/awardselect", function(request,response)
{
response.render("awardselect",{awardselect:request.session.awardlist});
});
// When Product detail requested , diplay it with session
app.get("/awarddetail", function(request,response)
{
var awardlist = request.session.awardlist;
//console.log('SFDFDFRFGFHGYHYYJJH*********')
var tosearch = support.getAwardByid(request.query.id, awardlist);
{
response.render("awarddetail",{awarddetail:tosearch});
}
});
// Have the app listen at port 8080
http.createServer(app).listen(3002);