diff options
| author | Bobby <[email protected]> | 2022-06-23 15:07:44 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2022-06-23 15:07:44 +0530 |
| commit | 2e0b8a471289f2e04286494a0a6333976b95e01a (patch) | |
| tree | 2fecab5129416fa8694140457eae6db6a8964882 | |
| parent | e743acd1cfc3a5c7a97279f6fa43af994cc6781d (diff) | |
| download | thatcomputerscientist-2e0b8a471289f2e04286494a0a6333976b95e01a.tar.xz thatcomputerscientist-2e0b8a471289f2e04286494a0a6333976b95e01a.zip | |
added cron job for connecting to the database
| -rw-r--r-- | package-lock.json | 30 | ||||
| -rw-r--r-- | package.json | 4 | ||||
| -rw-r--r-- | public/fonts/.DS_Store | bin | 0 -> 6148 bytes | |||
| -rw-r--r-- | server.js | 37 | ||||
| -rw-r--r-- | views/account.ejs | 2 | ||||
| -rw-r--r-- | views/partials/header.ejs | 2 |
6 files changed, 63 insertions, 12 deletions
diff --git a/package-lock.json b/package-lock.json index ea8d92f4..17e83ffa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,9 @@ "jsonwebtoken": "^8.5.1", "md5": "^2.3.0", "mysql2": "^2.3.3", - "node-fetch": "^3.2.5" + "node-cron": "^3.0.1", + "node-fetch": "^3.2.5", + "uuid": "^8.3.2" }, "devDependencies": { "nodemon": "^2.0.16" @@ -1543,6 +1545,14 @@ "node": ">= 0.6" } }, + "node_modules/node-cron": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/node-cron/-/node-cron-3.0.1.tgz", + "integrity": "sha512-RAWZTNn2M5KDIUV/389UX0EXsqvdFAwc9QwHQceh0Ga56dygqSRthqIjwpgZsoDspHGt2rkHdk9Z4RgfPMdALw==", + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/node-domexception": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", @@ -2320,6 +2330,14 @@ "node": ">= 0.4.0" } }, + "node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -3559,6 +3577,11 @@ "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==" }, + "node-cron": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/node-cron/-/node-cron-3.0.1.tgz", + "integrity": "sha512-RAWZTNn2M5KDIUV/389UX0EXsqvdFAwc9QwHQceh0Ga56dygqSRthqIjwpgZsoDspHGt2rkHdk9Z4RgfPMdALw==" + }, "node-domexception": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", @@ -4127,6 +4150,11 @@ "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" }, + "uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" + }, "vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", diff --git a/package.json b/package.json index 2ac6944c..d20de2f3 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,9 @@ "jsonwebtoken": "^8.5.1", "md5": "^2.3.0", "mysql2": "^2.3.3", - "node-fetch": "^3.2.5" + "node-cron": "^3.0.1", + "node-fetch": "^3.2.5", + "uuid": "^8.3.2" }, "devDependencies": { "nodemon": "^2.0.16" diff --git a/public/fonts/.DS_Store b/public/fonts/.DS_Store Binary files differnew file mode 100644 index 00000000..48331f8d --- /dev/null +++ b/public/fonts/.DS_Store @@ -1,11 +1,15 @@ const express = require("express"); const cors = require("cors"); -const bodyParser = require("body-parser"); -const cookieParser = require('cookie-parser'); -const flash = require('connect-flash'); -const expressSession = require('express-session'); +const cookieParser = require("cookie-parser"); +const flash = require("connect-flash"); +const expressSession = require("express-session"); +const mysql = require("mysql2"); const app = express(); const port = process.env.PORT || 3000; +const connectionURL = process.env.DATABASE_URL; +const validationString = process.env.AUTHORIZATION_STRING; +const cron = require("node-cron"); + require("dotenv").config(); // Middleware @@ -13,10 +17,12 @@ app.use(cors()); app.use(express.json()); app.use(cookieParser()); app.use(express.urlencoded({ extended: true })); -app.use(expressSession({ - cookie: { maxAge: 30 * 24 * 60 * 60 * 1000 }, - secret: process.env.AUTHORIZATION_STRING, -})); +app.use( + expressSession({ + cookie: { maxAge: 30 * 24 * 60 * 60 * 1000 }, + secret: process.env.AUTHORIZATION_STRING, + }) +); app.use(flash()); // Set Template Engine @@ -31,6 +37,21 @@ app.set("views", __dirname + "/views"); // Routes app.use("/", require("./routes")); +// Run a cron job every 6 days to connect to the database - so that the database does not sleep +cron.schedule("0 0 */6 * *", () => { + console.log("Cron job running"); + const connection = mysql.createConnection(connectionURL); + connection.connect(); + connection.query("SELECT 1", (err, results, fields) => { + if (err) { + console.log(err); + } else { + console.log("Database connected"); + } + }); + connection.end(); +}); + // Start server app.listen(port, () => { console.log(`Server started on port ${port}`); diff --git a/views/account.ejs b/views/account.ejs index 8d9be33f..d1b805b0 100644 --- a/views/account.ejs +++ b/views/account.ejs @@ -15,7 +15,7 @@ <div class="ac-sidebar"> <fieldset> <legend>Avatar</legend> - <img src="https://www.gravatar.com/avatar/<%= user.avatar %>?s=100" alt="<%= user.username %>'s avatar" width="200" height="200"/> + <img src="https://www.gravatar.com/avatar/<%= user.avatar %>?s=200" alt="<%= user.username %>'s avatar" width="200" height="200"/> </fieldset> <form method="post" action="/auth/changePassword"> <fieldset> diff --git a/views/partials/header.ejs b/views/partials/header.ejs index 96b0ac5f..74d9e117 100644 --- a/views/partials/header.ejs +++ b/views/partials/header.ejs @@ -6,7 +6,7 @@ <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="description" content="Welcome to the home of That Computer Scientist. I am Kumar Priyansh. This is my personal website where I share all of my thoughts, ideas, and experiences."> <title>That Computer Scientist - <%= title %></title> - <link preload rel="stylesheet" href="css/fonts.css"> + <link rel="stylesheet" href="css/fonts.css"> <link preload rel="stylesheet" href="css/main.css"> </head> <body>
\ No newline at end of file |
