diff --git a/server/db/db.js b/server/db/db.js index 929d8c2..0c31653 100644 --- a/server/db/db.js +++ b/server/db/db.js @@ -1,7 +1,21 @@ const pgPromise = require("pg-promise"); const config = require("../lib/config"); +const { ConnectionString } = require('connection-string'); -const pgp = pgPromise({}); -const DB = pgp(config.dbConnectionString); +const cnObj = new ConnectionString(config.dbConnectionString) +const cn = { + host: cnObj.hostname, + port: cnObj.port, + database: cnObj.path?.[0], + user: cnObj.user, + password: cnObj.password, + ssl: { + rejectUnauthorized: false, + }, +}; + +const pgp = pgPromise(); +const DB = pgp(cn); module.exports = DB; + diff --git a/server/db/init b/server/db/init index 3127fd2..566c1a1 100644 --- a/server/db/init +++ b/server/db/init @@ -3,6 +3,7 @@ drop table tweets; drop table authors; drop table media; drop table links; +drop table elites; create table elites ( id bigint unique, @@ -69,7 +70,7 @@ CREATE INDEX ideo_index ON elites (ideo); CREATE INDEX tweets_link_index -ON tweets (link); +ON tweets (link_preview_url); CREATE INDEX tweets_media_index_1 ON tweets (media_id_1); @@ -83,7 +84,7 @@ ON tweets (ds); CREATE INDEX usernames ON users (username); -GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO testuser; +GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO twee_user; -- initial data for elites table COPY elites(id, username, ideo) @@ -91,7 +92,4 @@ FROM './elites.csv' DELIMITER ',' CSV HEADER; --- some test data -insert into authors values (16129920, 'Rachel Maddow MSNBC', 'maddow', TRUE, 'https://pbs.twimg.com/profile_images/59437078/icon-200x200_normal.jpg', TRUE, -1); -insert into users values ('test', 'test-install-code', 2, 1); diff --git a/server/db/scraper.mjs b/server/db/scraper.mjs index 0549499..b731456 100644 --- a/server/db/scraper.mjs +++ b/server/db/scraper.mjs @@ -13,8 +13,9 @@ import pgPromise from "pg-promise"; const pgp = pgPromise({}); import { default as DB } from "./db.js"; +import { default as config } from "../lib/config.js" -const BEARER_TOKEN = process.env.BEARER_TOKEN; +const BEARER_TOKEN = config.twitterBearerToken; const WRITE_DB = true; @@ -338,12 +339,10 @@ const unwrapped_link = await getLinkPreview(test_link, { followRedirects: `follow`, }); -/* -Maddow +// Maddow test_fetch("16129920").then((result) => { console.log("fetched") }); -*/ // Fox news test_fetch("1367531").then((result) => { diff --git a/server/makefile b/server/makefile index 17ec447..5f702eb 100644 --- a/server/makefile +++ b/server/makefile @@ -1,5 +1,9 @@ start: - npm start + npx pm2 start bin/www + +list: + npx pm2 list + setup_node: install_nvm npm install diff --git a/server/package-lock.json b/server/package-lock.json index f591463..99c3f22 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -9,6 +9,7 @@ "version": "0.0.0", "dependencies": { "aws-sdk": "^2.1275.0", + "connection-string": "^4.3.6", "cookie-parser": "~1.4.4", "cors": "^2.8.5", "debug": "~2.6.9", @@ -341,6 +342,15 @@ "node": ">= 0.6.x" } }, + "node_modules/connection-string": { + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/connection-string/-/connection-string-4.3.6.tgz", + "integrity": "sha512-dwaq4BMeiIIWry/oQxjstPB7Xp0K1nGjaY8p6PHQB+J9ZJuIvNp7ux3Noupq0hMd/dqEHXkfdmmGFOKTbGKWmw==", + "engines": { + "node": ">=12", + "npm": ">=6" + } + }, "node_modules/constantinople": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/constantinople/-/constantinople-3.0.2.tgz", @@ -1987,6 +1997,11 @@ "resolved": "https://registry.npmjs.org/commander/-/commander-2.6.0.tgz", "integrity": "sha512-PhbTMT+ilDXZKqH8xbvuUY2ZEQNef0Q7DKxgoEKb4ccytsdvVVJmYqR0sGbi96nxU6oGrwEIQnclpK2NBZuQlg==" }, + "connection-string": { + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/connection-string/-/connection-string-4.3.6.tgz", + "integrity": "sha512-dwaq4BMeiIIWry/oQxjstPB7Xp0K1nGjaY8p6PHQB+J9ZJuIvNp7ux3Noupq0hMd/dqEHXkfdmmGFOKTbGKWmw==" + }, "constantinople": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/constantinople/-/constantinople-3.0.2.tgz", diff --git a/server/package.json b/server/package.json index d053994..3442d52 100644 --- a/server/package.json +++ b/server/package.json @@ -7,6 +7,7 @@ }, "dependencies": { "aws-sdk": "^2.1275.0", + "connection-string": "^4.3.6", "cookie-parser": "~1.4.4", "cors": "^2.8.5", "debug": "~2.6.9",