diff --git a/dataMigration/app.js b/dataMigration/app.js deleted file mode 100644 index 0679e25..0000000 --- a/dataMigration/app.js +++ /dev/null @@ -1,46 +0,0 @@ -const { Pool, Client } = require('pg') -const Pass = require('../env/config.js'); - -/* These files have been deleted to save space */ -// const Questions = require('./questions.csv'); -// const Answers = require('./answers.csv'); -// const A_Photos = require('./answers_photos.csv'); - -const pool = new Pool({ - user: 'postgres', - host: 'localhost', - database: 'atelier', - password: Pass.PASS, - port: 5432, -}); -pool.connect(); - -pool.query('CREATE TABLE questions(q_id SERIAL, question_id numerical, a_body VARCHAR(500), date timestamp, username VARCHAR(25), user_email VARCHAR(25), reported integer, helpful_count integer, PRIMARY KEY(q_id)', (err, res) => { - console.log(err, res); -}).then(res => { - pool.query("COPY questions(q_id, question_id, a_body, date, username, user_email, reported, helpful_count) FROM Answers DELIMITER ',' CSV HEADER;", (err, res) => { - console.log(err, res) - }).then(res => { - pool.query("alter table questions alter column date type date using to_timestamp(date / 1000)::date;"); - console.log(err, res); - }) -}).catch(err => console.log(err)); - -pool.query('CREATE TABLE answers(a_id SERIAL, product_id numerical, q_body VARCHAR(500), date timestamp, username VARCHAR(25), user_email VARCHAR(25), reported integer, helpful_count integer, PRIMARY KEY(a_id)', (err, res) => { - console.log(err, res); -}).then(res => { - pool.query("COPY answers(a_id, product_id, q_body, date, username, user_email, reported, helpful_count) FROM Answers DELIMITER ',' CSV HEADER;", (err, res) => { - console.log(err, res) - }).then(res => { - pool.query("alter table answers alter column date type date using to_timestamp(date / 1000)::date;"); - console.log(err, res); - }) -}).catch(err => console.log(err)); - -pool.query('CREATE TABLE answers_photos(p_id SERIAL, answers_id numerical, url varchar(200) PRIMARY KEY(p_id)', (err, res) => { - console.log(err, res); -}).then(res => { - pool.query("COPY answers(a_id, answers_id, url) FROM A_Photos DELIMITER ',' CSV HEADER;", (err, res) => { - console.log(err, res) - }) -}).catch(err => console.log(err)); \ No newline at end of file diff --git a/dataMigration/postgresql.js b/dataMigration/postgresql.js new file mode 100644 index 0000000..77f4ef8 --- /dev/null +++ b/dataMigration/postgresql.js @@ -0,0 +1,46 @@ +// const { Pool, Client } = require('pg') +// const Pass = require('../env/config.js'); + +// /* These files have been deleted to save space */ +// // const Questions = require('./questions.csv'); +// // const Answers = require('./answers.csv'); +// // const A_Photos = require('./answers_photos.csv'); + +// const pool = new Pool({ +// user: 'postgres', +// host: 'localhost', +// database: 'atelier', +// password: Pass.PASS, +// port: 5432, +// }); +// pool.connect(); + +// pool.query('CREATE TABLE questions(q_id SERIAL, question_id numerical, a_body VARCHAR(500), date timestamp, username VARCHAR(25), user_email VARCHAR(25), reported integer, helpful_count integer, PRIMARY KEY(q_id)', (err, res) => { +// console.log(err, res); +// }).then(res => { +// pool.query("COPY questions(q_id, question_id, a_body, date, username, user_email, reported, helpful_count) FROM Answers DELIMITER ',' CSV HEADER;", (err, res) => { +// console.log(err, res) +// }).then(res => { +// pool.query("alter table questions alter column date type date using to_timestamp(date / 1000)::date;"); +// console.log(err, res); +// }) +// }).catch(err => console.log(err)); + +// pool.query('CREATE TABLE answers(a_id SERIAL, product_id numerical, q_body VARCHAR(500), date timestamp, username VARCHAR(25), user_email VARCHAR(25), reported integer, helpful_count integer, PRIMARY KEY(a_id)', (err, res) => { +// console.log(err, res); +// }).then(res => { +// pool.query("COPY answers(a_id, product_id, q_body, date, username, user_email, reported, helpful_count) FROM Answers DELIMITER ',' CSV HEADER;", (err, res) => { +// console.log(err, res) +// }).then(res => { +// pool.query("alter table answers alter column date type date using to_timestamp(date / 1000)::date;"); +// console.log(err, res); +// }) +// }).catch(err => console.log(err)); + +// pool.query('CREATE TABLE answers_photos(p_id SERIAL, answers_id numerical, url varchar(200) PRIMARY KEY(p_id)', (err, res) => { +// console.log(err, res); +// }).then(res => { +// pool.query("COPY answers(a_id, answers_id, url) FROM A_Photos DELIMITER ',' CSV HEADER;", (err, res) => { +// console.log(err, res) +// }) +// }).catch(err => console.log(err)); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 9e09249..aa0c060 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,9 +12,11 @@ "axios": "^0.27.2", "cloudinary-core": "^2.13.0", "cloudinary-react": "^1.8.1", + "cors": "^2.8.5", "date-fns": "^2.29.2", "dotenv": "^16.0.1", "express": "^4.18.1", + "morgan": "^1.10.0", "nodemon": "^2.0.19", "pg": "^8.8.0", "react": "^18.2.0", @@ -3408,6 +3410,22 @@ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, + "node_modules/basic-auth": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz", + "integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==", + "dependencies": { + "safe-buffer": "5.1.2" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/basic-auth/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + }, "node_modules/big.js": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", @@ -3860,6 +3878,18 @@ "semver": "bin/semver.js" } }, + "node_modules/cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -6706,6 +6736,45 @@ "node": "*" } }, + "node_modules/morgan": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.10.0.tgz", + "integrity": "sha512-AbegBVI4sh6El+1gNwvD5YIck7nSA36weD7xvIxG4in80j/UoK8AEGaWnnz8v1GxonMCltmlNs5ZKbGvl9b1XQ==", + "dependencies": { + "basic-auth": "~2.0.1", + "debug": "2.6.9", + "depd": "~2.0.0", + "on-finished": "~2.3.0", + "on-headers": "~1.0.2" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/morgan/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/morgan/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + }, + "node_modules/morgan/node_modules/on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "integrity": "sha512-ikqdkGAAyf/X/gPhXGvfgAytDZtDbr+bkNUJ0N9h5MI/dmdgCs3l6hoHrcUv41sRKew3jIwrp4qQDXiK99Utww==", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -6894,6 +6963,14 @@ "node": ">= 0.8" } }, + "node_modules/on-headers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz", + "integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -11105,6 +11182,21 @@ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, + "basic-auth": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz", + "integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==", + "requires": { + "safe-buffer": "5.1.2" + }, + "dependencies": { + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + } + } + }, "big.js": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", @@ -11451,6 +11543,15 @@ } } }, + "cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "requires": { + "object-assign": "^4", + "vary": "^1" + } + }, "cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -13567,6 +13668,41 @@ "brace-expansion": "^1.1.7" } }, + "morgan": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.10.0.tgz", + "integrity": "sha512-AbegBVI4sh6El+1gNwvD5YIck7nSA36weD7xvIxG4in80j/UoK8AEGaWnnz8v1GxonMCltmlNs5ZKbGvl9b1XQ==", + "requires": { + "basic-auth": "~2.0.1", + "debug": "2.6.9", + "depd": "~2.0.0", + "on-finished": "~2.3.0", + "on-headers": "~1.0.2" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + }, + "on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "integrity": "sha512-ikqdkGAAyf/X/gPhXGvfgAytDZtDbr+bkNUJ0N9h5MI/dmdgCs3l6hoHrcUv41sRKew3jIwrp4qQDXiK99Utww==", + "requires": { + "ee-first": "1.1.1" + } + } + } + }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -13704,6 +13840,11 @@ "ee-first": "1.1.1" } }, + "on-headers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz", + "integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==" + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", diff --git a/package.json b/package.json index e016379..c462520 100644 --- a/package.json +++ b/package.json @@ -21,9 +21,11 @@ "axios": "^0.27.2", "cloudinary-core": "^2.13.0", "cloudinary-react": "^1.8.1", + "cors": "^2.8.5", "date-fns": "^2.29.2", "dotenv": "^16.0.1", "express": "^4.18.1", + "morgan": "^1.10.0", "nodemon": "^2.0.19", "pg": "^8.8.0", "react": "^18.2.0", diff --git a/server/db-mod.js b/server/db-mod.js index 02a9f70..e9b4cc0 100644 --- a/server/db-mod.js +++ b/server/db-mod.js @@ -13,7 +13,6 @@ pool.connect(); module.exports = { getQs: (req) => { - console.log("models.getQs works"); // pool.query("SELECT json_agg(q) FROM q", (err, res) => { // console.log(err, res); // }) diff --git a/server/index.js b/server/index.js index 7948695..c5059f4 100644 --- a/server/index.js +++ b/server/index.js @@ -2,10 +2,20 @@ require("dotenv").config(); const express = require("express"); const app = express(); const path = require("path"); +const router = require("./routes"); + +// var morgan = require('morgan'); +// var cors = require('cors'); + +// app.use(morgan('dev')); +// app.use(cors()); app.use(express.json()); app.use(express.static(path.join(__dirname, "../client/dist"))); +//set up routes +app.use(router); + const PORT = process.env.PORT || 3000; app.listen(PORT);