Updated toothpaste
This commit is contained in:
parent
20807fdacc
commit
e24bdf5317
33
app.js
33
app.js
@ -2,6 +2,7 @@ var bodyParser = require('body-parser');
|
|||||||
var express = require('express');
|
var express = require('express');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var connection = require("./js/mysql.js");
|
var connection = require("./js/mysql.js");
|
||||||
|
var mysql = require("mysql");
|
||||||
|
|
||||||
var rhg = require('random-hash-generator');
|
var rhg = require('random-hash-generator');
|
||||||
|
|
||||||
@ -19,36 +20,10 @@ app.use(bodyParser.urlencoded({
|
|||||||
}));
|
}));
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
|
|
||||||
const PORT = 8081;
|
const PORT = 8077;
|
||||||
var types;
|
var types;
|
||||||
|
|
||||||
function connect() {
|
|
||||||
// if (connection !== undefined && connection !== null) {
|
|
||||||
// connection.destroy();
|
|
||||||
// }
|
|
||||||
|
|
||||||
connection.connect(function(err) {
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
connect();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
connection.on('error', function(err) {
|
|
||||||
console.log('db error', err);
|
|
||||||
if (err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually
|
|
||||||
connect();
|
|
||||||
}
|
|
||||||
else { // connnection idle timeout (the wait_timeout
|
|
||||||
throw err; // server variable configures this)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
connect();
|
|
||||||
|
|
||||||
function query(str, callback) {
|
function query(str, callback) {
|
||||||
query(str, [], callback);
|
query(str, [], callback);
|
||||||
@ -66,7 +41,7 @@ query("SELECT * FROM types", function(err, result) {
|
|||||||
|
|
||||||
|
|
||||||
app.port = PORT;
|
app.port = PORT;
|
||||||
app.host = "127.0.0.1";
|
app.host = "0.0.0.0";
|
||||||
|
|
||||||
function generateId(data) {
|
function generateId(data) {
|
||||||
pastesThisSession++;
|
pastesThisSession++;
|
||||||
@ -195,5 +170,5 @@ app.get("/:path", handleRequest);
|
|||||||
app.get("/:path/:option", handleRequest);
|
app.get("/:path/:option", handleRequest);
|
||||||
|
|
||||||
app.listen(PORT, "127.0.0.1", 511, function() {
|
app.listen(PORT, "127.0.0.1", 511, function() {
|
||||||
|
console.log("Static Webserver started on port "+PORT);
|
||||||
});
|
});
|
||||||
|
|||||||
31
js/mysql.js
31
js/mysql.js
@ -2,8 +2,33 @@ var mysql = require('mysql');
|
|||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
|
||||||
var file = null;
|
var file = null;
|
||||||
|
var connectionConfig;
|
||||||
var connection = null;
|
var connection = null;
|
||||||
|
|
||||||
|
function handleDisconnect() {
|
||||||
|
connection = mysql.createConnection(connectionConfig);
|
||||||
|
|
||||||
|
connection.connect(function(err) {
|
||||||
|
if(err) {
|
||||||
|
console.log('error when connecting to db:', err);
|
||||||
|
setTimeout(handleDisconnect, 2000);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log("Connected to MySQL database ( "+connectionConfig.user+"@"+connectionConfig.host+"/"+connectionConfig.database+" )");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
connection.on('error', function(err) {
|
||||||
|
console.log('db error', err);
|
||||||
|
if(err.code === 'PROTOCOL_CONNECTION_LOST') {
|
||||||
|
handleDisconnect();
|
||||||
|
} else if(err.code === 'ECONNRESET'){
|
||||||
|
handleDisconnect();
|
||||||
|
} else{
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
file = fs.readFileSync("./config.json");
|
file = fs.readFileSync("./config.json");
|
||||||
}
|
}
|
||||||
@ -14,12 +39,14 @@ catch(exception) {
|
|||||||
if(file != null) {
|
if(file != null) {
|
||||||
var json = JSON.parse(file);
|
var json = JSON.parse(file);
|
||||||
|
|
||||||
connection = mysql.createConnection({
|
connectionConfig = {
|
||||||
host: json.host,
|
host: json.host,
|
||||||
database: json.database,
|
database: json.database,
|
||||||
user: json.user,
|
user: json.user,
|
||||||
password: json.password
|
password: json.password
|
||||||
});
|
};
|
||||||
|
|
||||||
|
handleDisconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
1
start.sh
Executable file
1
start.sh
Executable file
@ -0,0 +1 @@
|
|||||||
|
screen -dmS paste 'while true; do node ./app.js; done'
|
||||||
@ -69,8 +69,8 @@
|
|||||||
viewModel.selectedTypeName = ko.observable();
|
viewModel.selectedTypeName = ko.observable();
|
||||||
viewModel.selectedTypeIndex = ko.observable();
|
viewModel.selectedTypeIndex = ko.observable();
|
||||||
|
|
||||||
viewModel.selectedTypeName(viewModel.types[0].type);
|
viewModel.selectedTypeName(viewModel.types[31].type);
|
||||||
viewModel.selectedTypeIndex(0);
|
viewModel.selectedTypeIndex(31);
|
||||||
|
|
||||||
$("#pasteButton").on("click", function(){
|
$("#pasteButton").on("click", function(){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@ -89,7 +89,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}) ;
|
});
|
||||||
|
|
||||||
$("#typeList").bind( "click" , function(element){
|
$("#typeList").bind( "click" , function(element){
|
||||||
selectedType = viewModel.types[$(element.target).attr("typeindex")];
|
selectedType = viewModel.types[$(element.target).attr("typeindex")];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user