dockerized
This commit is contained in:
parent
f97f56f837
commit
dbd6e9db5a
8 changed files with 14 additions and 35 deletions
1
Procfile
1
Procfile
|
|
@ -1 +0,0 @@
|
||||||
web: node index.js
|
|
||||||
2
dat
2
dat
|
|
@ -1,2 +0,0 @@
|
||||||
2020-1-17, sander, 1
|
|
||||||
2020-1-17, sander, 1
|
|
||||||
1
data/data.csv
Normal file
1
data/data.csv
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
2020-1-20, sander, 1
|
||||||
|
20
encrypt
20
encrypt
|
|
@ -1,20 +0,0 @@
|
||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
const bcrypt = require('bcrypt');
|
|
||||||
|
|
||||||
if (process.argv.length === 0) {
|
|
||||||
console.log("Usage: encrypt <password>");
|
|
||||||
} else {
|
|
||||||
let plain= process.argv[2];
|
|
||||||
let hash=cryptPassword(plain);
|
|
||||||
console.log(hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
function cryptPassword(password) {
|
|
||||||
let salt = bcrypt.genSaltSync(10);
|
|
||||||
return bcrypt.hashSync(password, salt);
|
|
||||||
};
|
|
||||||
|
|
||||||
function comparePassword(plainPass, hashword) {
|
|
||||||
return bcrypt.compareSync(plainPass, hashword);
|
|
||||||
};
|
|
||||||
|
|
@ -5,9 +5,9 @@
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "12.x"
|
"node": "12.x"
|
||||||
},
|
},
|
||||||
"main": "src/index.js",
|
"main": "src/server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node src/index.js",
|
"start": "node src/server.js",
|
||||||
"test": "node_modules/.bin/tape test/*.js"
|
"test": "node_modules/.bin/tape test/*.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
||||||
|
|
@ -18,17 +18,17 @@ function handle(event, next) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function happy() {
|
function happy() {
|
||||||
emotion().value = "3";
|
emotion().value = "1";
|
||||||
submit();
|
submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
function unsure() {
|
function unsure() {
|
||||||
emotion().value = "2";
|
emotion().value = "0";
|
||||||
submit();
|
submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
function sad() {
|
function sad() {
|
||||||
emotion().value = "1";
|
emotion().value = "-1";
|
||||||
submit();
|
submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ const express = require('express');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const bodyParser = require('body-parser');
|
const bodyParser = require('body-parser');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const PORT = process.env.PORT || 5000;
|
const PORT = process.env.PORT || 5555;
|
||||||
|
const DATA_PATH = process.env.DATA_PATH || "data";
|
||||||
|
|
||||||
express()
|
express()
|
||||||
.use(express.urlencoded({extended: true}))
|
.use(express.urlencoded({extended: true}))
|
||||||
|
|
@ -18,7 +19,7 @@ function appendToStorage(req, res) {
|
||||||
if (req.body.username === '') {
|
if (req.body.username === '') {
|
||||||
res.render('pages/error');
|
res.render('pages/error');
|
||||||
} else {
|
} else {
|
||||||
fs.appendFile("dat", req.body.timestamp + ", " + req.body.username + ", " + req.body.emotion + "\n", err => {
|
fs.appendFile(DATA_PATH + "/data.csv", req.body.timestamp + ", " + req.body.username + ", " + req.body.emotion + "\n", err => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return console.log(err);
|
return console.log(err);
|
||||||
}
|
}
|
||||||
|
|
@ -28,7 +29,7 @@ function appendToStorage(req, res) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendData(req, res) {
|
function sendData(req, res) {
|
||||||
fs.readFile("dat", (err, data) => {
|
fs.readFile("data.csv", (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
res.render('pages/error');
|
res.render('pages/error');
|
||||||
|
|
@ -5,7 +5,7 @@ const test = require('tape');
|
||||||
const env = Object.assign({}, process.env, {PORT: 5000});
|
const env = Object.assign({}, process.env, {PORT: 5000});
|
||||||
|
|
||||||
test('main page', (assert) => {
|
test('main page', (assert) => {
|
||||||
const server = spawn('node', ['src/index.js'], {env});
|
const server = spawn('node', ['src/server.js'], {env});
|
||||||
server.stdout.on('data', _ => {
|
server.stdout.on('data', _ => {
|
||||||
request('http://127.0.0.1:5000', (error, response, body) => {
|
request('http://127.0.0.1:5000', (error, response, body) => {
|
||||||
server.kill();
|
server.kill();
|
||||||
|
|
@ -20,7 +20,7 @@ test('main page', (assert) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('submit emotion', (assert) => {
|
test('submit emotion', (assert) => {
|
||||||
const server = spawn('node', ['src/index.js'], {env});
|
const server = spawn('node', ['src/server.js'], {env});
|
||||||
server.stdout.on('data', _ => {
|
server.stdout.on('data', _ => {
|
||||||
request.post({url: 'http://127.0.0.1:5000/submit-form', form:{username:'sander', password:'boompje', emotion:1, timestamp: '20191212' }}, (error, response, body) => {
|
request.post({url: 'http://127.0.0.1:5000/submit-form', form:{username:'sander', password:'boompje', emotion:1, timestamp: '20191212' }}, (error, response, body) => {
|
||||||
server.kill();
|
server.kill();
|
||||||
|
|
@ -34,7 +34,7 @@ test('submit emotion', (assert) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('get data', (assert) => {
|
test('get data', (assert) => {
|
||||||
const server = spawn('node', ['src/index.js'], {env});
|
const server = spawn('node', ['src/server.js'], {env});
|
||||||
server.stdout.on('data', _ => {
|
server.stdout.on('data', _ => {
|
||||||
request.post({url: 'http://127.0.0.1:5000/submit-form', form:{username:'sander', password:'boompje', emotion:1, timestamp: '20191212' }});
|
request.post({url: 'http://127.0.0.1:5000/submit-form', form:{username:'sander', password:'boompje', emotion:1, timestamp: '20191212' }});
|
||||||
request('http://127.0.0.1:5000/data', (error, response, body) => {
|
request('http://127.0.0.1:5000/data', (error, response, body) => {
|
||||||
|
|
@ -49,7 +49,7 @@ test('get data', (assert) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('empty submit error', (assert) => {
|
test('empty submit error', (assert) => {
|
||||||
const server = spawn('node', ['src/index.js'], {env});
|
const server = spawn('node', ['src/server.js'], {env});
|
||||||
server.stdout.on('data', _ => {
|
server.stdout.on('data', _ => {
|
||||||
request.post({url: 'http://127.0.0.1:5000/submit-form', form:{}}, (error, response, body) => {
|
request.post({url: 'http://127.0.0.1:5000/submit-form', form:{}}, (error, response, body) => {
|
||||||
server.kill();
|
server.kill();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue