Skip to content

Commit

Permalink
Merge pull request #202 from AltCamp/110-feature-implement-caching
Browse files Browse the repository at this point in the history
feature: implement caching
  • Loading branch information
tobisupreme committed Jul 11, 2023
2 parents 1e72313 + 6b15d9e commit 07484c0
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 137 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
ecmaVersion: 'latest',
},
globals: {
cache: 'readonly',
logger: 'readonly',
},
rules: {
Expand Down
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const app = express();
initializeSentry();

global.logger = Logger.createLogger({ label: ALT_CAMP });
require('./src/common/cache');

const appConfig = (app) => {
app.use(Sentry.Handlers.requestHandler());
Expand Down
13 changes: 7 additions & 6 deletions bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
*/

var app = require('../app');
var debug = require('debug')('study-buddy:server');
var http = require('http');
const connectDatabase = require('../utils/db');

const config = require('../config');
const { app: appConfig, db } = require('../config');

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(config.app.port);
var port = normalizePort(appConfig.port);
app.set('port', port);

/**
Expand All @@ -28,7 +27,10 @@ var server = http.createServer(app);
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
cache.connect();
connectDatabase(db.name).then(() => {
server.listen(port);
});
server.on('error', onError);
server.on('listening', onListening);

Expand Down Expand Up @@ -83,8 +85,7 @@ function onError(error) {
*/

async function onListening() {
connectDatabase(config.db.name);
var addr = server.address();
var bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port;
debug('Listening on ' + bind);
logger.info('Listening on ' + bind);
}
3 changes: 3 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ module.exports = {
refresh_token: process.env.GOOGLE_REFRESH_TOKEN,
access_token: process.env.GOOGLE_ACCESS_TOKEN,
},
redis: {
url: process.env.REDIS_URL,
},
smtpConfig: {
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT,
Expand Down
5 changes: 5 additions & 0 deletions constant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ module.exports = {
PROFILEPICTURE: 1024 * 512,
},

REDIS: {
CONNECTION_ERROR: 'Redis connection error',
KEEPING_ALIVE: 'Redis - keeping alive',
},

VALID_IMAGE_FORMATS: {
PNG: 'png',
JPG: 'jpg',
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '0.1'
services:
redis:
image: redis:latest
ports:
- '6379:6379'
volumes:
- redis:/data
volumes:
redis:
5 changes: 4 additions & 1 deletion example.env
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ GOOGLE_CLIENT_SECRET=
GOOGLE_REFRESH_TOKEN=
GOOGLE_ACCESS_TOKEN=


# CORS
CORS_ALLOWED_ORIGINS=

EMAIL_VERIFICATION_OTP_VALIDITY=
PASSWORD_RESET_OTP_VALIDITY=

# REDIS
REDIS_URL=redis://localhost:6379
Loading

0 comments on commit 07484c0

Please sign in to comment.