Skip to content
Snippets Groups Projects
Commit f026c909 authored by Josefine Wegert's avatar Josefine Wegert
Browse files

cookies implemented for passing checked files from form

parent 8e9fc1e7
No related branches found
No related tags found
No related merge requests found
var express = require('express');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var exec = require('child_process').exec;
......@@ -21,28 +22,38 @@ app.use(bodyParser.urlencoded({
}));
app.use(bodyParser.json());
app.use(logger("short"));
app.use(cookieParser());
//set handlebars as view engine
app.engine('.hbs', exphbs({extname: '.hbs'}));
app.set('view engine', '.hbs');
//routes
app.get('/', function(req, res){
res.render('home', {downloadFiles: downloadNames});
});
app.post('/waiting', function(req, res){
console.log("frontend in /waiting", req.body['explorviz-ui-backend']);
app.post('/', function(req, res, next){
var checkedFiles = Object.keys(req.body);
console.log("checkedFiles", checkedFiles);
res.render('download', {test: checkedFiles});
if(typeof checkedFiles !== 'undefined' && checkedFiles.length > 0){
console.log('files were checked');
//set cookie to pass checked files for download
res.cookie('fileCookie', checkedFiles).render('download');
}
else {
console.log('files were not checked');
res.render('home', {downloadFiles: downloadNames});
}
});
app.get('/download', function(req, res){
console.log("frontend in /download", req.body);
console.log("checkedFiles in /download", req.cookies.fileCookie);
// if (typeof req.body.backend !== 'undefined'){
console.log("inside backend branch");
exec('cd /home/jweg/git/explorviz-ui-backend && mvn compile war:war', (error, stdout, stderr) => {
......
......@@ -12,6 +12,7 @@
"adm-zip": "^0.4.7",
"body-parser": "^1.17.1",
"child_process": "^1.0.2",
"cookie-parser": "^1.4.3",
"express": "^4.15.2",
"express-handlebars": "^3.0.0",
"fs": "0.0.1-security",
......
<form action="/waiting" method="post">
<form action="/" method="post">
Choose which files to compile into your custom build of ExplorViz:<br>
{{#each downloadFiles as |item|}}
<input type="checkbox" name={{item}} value={{item}}>{{item}}<br>
{{/each}}
<br>
<a >
<button type="submit">Create Build and Download Zip</a>
<button type="submit">Create Build and Download Zip</button>
</form>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment