Advertisement
Guest User

Untitled

a guest
May 24th, 2018
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. var express = require('express');
  2. var app = express();
  3. var pg = require('pg');
  4.  
  5. var conString = "postgres://ibehhwmz:EfgLajCRSw4tUqLeHEGonaxJPdBqURMp@packy.db.elephantsql.com:5432/ibehhwmz";
  6.  
  7. const config = {
  8. host: 'packy.db.elephantsql.com',
  9. user: 'ibehhwmz',
  10. database: 'ibehhwmz',
  11. password: 'EfgLajCRSw4tUqLeHEGonaxJPdBqURMp',
  12. port: 5432
  13. };
  14.  
  15. const pool = new pg.Pool(config);
  16.  
  17. var id = 441;
  18.  
  19. var bodyParser = require('body-parser')
  20. app.use( bodyParser.json() ); // to support JSON-encoded bodies
  21. app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
  22. extended: true
  23. }));
  24.  
  25. app.get('/', function (req, res) {
  26. res.sendFile( __dirname + "/" + "main.html" );
  27. })
  28.  
  29. app.get('/main.html', function (req, res) {
  30. res.sendFile( __dirname + "/" + "main.html" );
  31. })
  32.  
  33. app.get('/survey-creation.html', function (req, res) {
  34. res.sendFile( __dirname + "/" + "survey-creation.html" );
  35. })
  36.  
  37. app.get('/survey-info.html', function (req, res) {
  38. res.sendFile( __dirname + "/" + "survey-info.html" );
  39. })
  40.  
  41. app.get('/survey-fill.html', function (req, res) {
  42. res.sendFile( __dirname + "/" + "survey-fill.html" );
  43. })
  44.  
  45. app.get('/survey-statistics.html', function (req, res) {
  46. res.sendFile( __dirname + "/" + "survey-statistics.html" );
  47. })
  48.  
  49. app.get('/survey-validation.html', function (req, res) {
  50. res.sendFile( __dirname + "/" + "survey-validation.html" );
  51. })
  52.  
  53. app.get('/project-page.html', function (req, res) {
  54. res.sendFile( __dirname + "/" + "project-page.html" );
  55. })
  56.  
  57. app.get('/projects.html', function (req, res) {
  58. res.sendFile( __dirname + "/" + "projects.html" );
  59. })
  60.  
  61. app.get('/workers.html', function (req, res) {
  62. res.sendFile( __dirname + "/" + "workers.html" );
  63. })
  64.  
  65. app.get('/login.html', function(req, res) {
  66. res.sendFile( __dirname + "/" + "login.html");
  67. })
  68.  
  69. app.get('/get_workers', function(req, res) {
  70. pool.connect(function(err,client,done) {
  71. if(err){
  72. console.log("not able to get connection "+ err);
  73. res.status(400).send(err);
  74. }
  75. client.query('SELECT * from workers' ,function(err,result) {
  76. //call `done()` to release the client back to the pool
  77. done();
  78. if(err){
  79. console.log(err);
  80. res.status(400).send(err);
  81. }
  82. res.status(200).send(result.rows);
  83. });
  84. });
  85. })
  86.  
  87. app.post('/createNewZam', function(req, res) {
  88. pool.connect(function(err,client,done) {
  89. if(err){
  90. console.log("not able to get connection "+ err);
  91. res.status(400).send(err);
  92. }
  93. var queryText = 'INSERT INTO workers(name, "osobniCislo", email, uvazek, id) VALUES($1, $2, $3, $4, $5)'
  94. client.query(queryText, [req.body.name, req.body.osobniCislo, req.body.email, req.body.uvazek, ++id], function(err, result) {
  95. if(err){
  96. console.log(err);
  97. }
  98. else {
  99. res.status(200);
  100. }
  101. });
  102. });
  103. })
  104.  
  105. app.get('*', function(req, res){
  106. res.sendFile( __dirname + "/" + "404.html" );
  107. });
  108.  
  109. var port = process.env.PORT || 8888
  110. app.listen(port, function() {
  111. console.log("To view your app, open this link in your browser: http://localhost:" + port);
  112. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement