Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require('express');
- var app = express();
- var pg = require('pg');
- var conString = "postgres://ibehhwmz:EfgLajCRSw4tUqLeHEGonaxJPdBqURMp@packy.db.elephantsql.com:5432/ibehhwmz";
- const config = {
- host: 'packy.db.elephantsql.com',
- user: 'ibehhwmz',
- database: 'ibehhwmz',
- password: 'EfgLajCRSw4tUqLeHEGonaxJPdBqURMp',
- port: 5432
- };
- const pool = new pg.Pool(config);
- var id = 441;
- var bodyParser = require('body-parser')
- app.use( bodyParser.json() ); // to support JSON-encoded bodies
- app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
- extended: true
- }));
- app.get('/', function (req, res) {
- res.sendFile( __dirname + "/" + "main.html" );
- })
- app.get('/main.html', function (req, res) {
- res.sendFile( __dirname + "/" + "main.html" );
- })
- app.get('/survey-creation.html', function (req, res) {
- res.sendFile( __dirname + "/" + "survey-creation.html" );
- })
- app.get('/survey-info.html', function (req, res) {
- res.sendFile( __dirname + "/" + "survey-info.html" );
- })
- app.get('/survey-fill.html', function (req, res) {
- res.sendFile( __dirname + "/" + "survey-fill.html" );
- })
- app.get('/survey-statistics.html', function (req, res) {
- res.sendFile( __dirname + "/" + "survey-statistics.html" );
- })
- app.get('/survey-validation.html', function (req, res) {
- res.sendFile( __dirname + "/" + "survey-validation.html" );
- })
- app.get('/project-page.html', function (req, res) {
- res.sendFile( __dirname + "/" + "project-page.html" );
- })
- app.get('/projects.html', function (req, res) {
- res.sendFile( __dirname + "/" + "projects.html" );
- })
- app.get('/workers.html', function (req, res) {
- res.sendFile( __dirname + "/" + "workers.html" );
- })
- app.get('/login.html', function(req, res) {
- res.sendFile( __dirname + "/" + "login.html");
- })
- app.get('/get_workers', function(req, res) {
- pool.connect(function(err,client,done) {
- if(err){
- console.log("not able to get connection "+ err);
- res.status(400).send(err);
- }
- client.query('SELECT * from workers' ,function(err,result) {
- //call `done()` to release the client back to the pool
- done();
- if(err){
- console.log(err);
- res.status(400).send(err);
- }
- res.status(200).send(result.rows);
- });
- });
- })
- app.post('/createNewZam', function(req, res) {
- pool.connect(function(err,client,done) {
- if(err){
- console.log("not able to get connection "+ err);
- res.status(400).send(err);
- }
- var queryText = 'INSERT INTO workers(name, "osobniCislo", email, uvazek, id) VALUES($1, $2, $3, $4, $5)'
- client.query(queryText, [req.body.name, req.body.osobniCislo, req.body.email, req.body.uvazek, ++id], function(err, result) {
- if(err){
- console.log(err);
- }
- else {
- res.status(200);
- }
- });
- });
- })
- app.get('*', function(req, res){
- res.sendFile( __dirname + "/" + "404.html" );
- });
- var port = process.env.PORT || 8888
- app.listen(port, function() {
- console.log("To view your app, open this link in your browser: http://localhost:" + port);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement