Add docker-compose, redis and redis-connect middleware

master
Ian Mancini 4 years ago
parent 9caa9c1a87
commit b2e2ec3073

203
.gitignore vendored

@ -1,5 +1,200 @@
node_modules # Created by https://www.toptal.com/developers/gitignore/api/node,vim,emacs,linux
package-lock.json # Edit at https://www.toptal.com/developers/gitignore?templates=node,vim,emacs,linux
yarn.lock
### Emacs ###
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*
# Org-mode
.org-id-locations
*_archive
# flymake-mode
*_flymake.*
# eshell files
/eshell/history
/eshell/lastdir
# elpa packages
/elpa/
# reftex files
*.rel
# AUCTeX auto folder
/auto/
# cask packages
.cask/
dist/
# Flycheck
flycheck_*.el
# server auth directory
/server/
# projectiles files
.projectile
# directory configuration
.dir-locals.el
# network security
/network-security.data
### Linux ###
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
.env*.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist dist
.DS_Store
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
### Vim ###
# Swap
[._]*.s[a-v][a-z]
!*.svg # comment out if you don't need vector files
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
# Session
Session.vim
Sessionx.vim
# Temporary
.netrwhist
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~
# End of https://www.toptal.com/developers/gitignore/api/node,vim,emacs,linux

@ -0,0 +1,13 @@
version: '3.1'
services:
redis:
container_name: redis
image: redis
restart: always
ports:
- 6379:6379
command: >
--requirepass ${REDIS_PASSWORD}
volumes:
- ./docker/redis:/data

@ -0,0 +1,23 @@
POSTGRES_PASSWORD=
POSTGRES_USER=socialnetwork
POSTGRES_DB=socialnetwork
REDIS_PASSWORD=
JWT_SECRET=
FACEBOOK_CLIENT_ID=
FACEBOOK_CALLBACK_URL=
FACEBOOK_CLIENT_SECRET=
GMAIL_ADDRESS=
GMAIL_OAUTH_CLIENT_ID=
GMAIL_OAUTH_PROJECT_ID=
GMAIL_OAUTH_CLIENT_SECRET=
GMAIL_OAUTH_REDIRECT_URL=
GMAIL_CODE=
GMAIL_ACCESS_TOKEN=
GMAIL_REFRESH_TOKEN=
GMAIL_EXPIRY_DATE=

10465
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -10,17 +10,24 @@
"@react-ssr/core": "^0.21.18", "@react-ssr/core": "^0.21.18",
"@react-ssr/express": "^0.21.18", "@react-ssr/express": "^0.21.18",
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"connect-redis": "^5.0.0",
"cookie-parser": "^1.4.5", "cookie-parser": "^1.4.5",
"dotenv": "^8.2.0",
"express": "^4.17.1", "express": "^4.17.1",
"express-session": "^1.17.1",
"react": "^16.13.0", "react": "^16.13.0",
"react-dom": "^16.13.0" "react-dom": "^16.13.0",
"redis": "^3.0.2"
}, },
"devDependencies": { "devDependencies": {
"@types/connect-redis": "0.0.14",
"@types/cookie-parser": "^1.4.2", "@types/cookie-parser": "^1.4.2",
"@types/express": "^4.17.1", "@types/express": "^4.17.1",
"@types/express-session": "^1.17.0",
"@types/node": "^12.11.6", "@types/node": "^12.11.6",
"@types/react": "^16.9.11", "@types/react": "^16.9.11",
"@types/react-dom": "^16.9.4", "@types/react-dom": "^16.9.4",
"@types/redis": "^2.8.27",
"cross-env": "^7.0.2", "cross-env": "^7.0.2",
"ts-node-dev": "^1.0.0-pre.44", "ts-node-dev": "^1.0.0-pre.44",
"typescript": "^3.8.3" "typescript": "^3.8.3"

@ -1,17 +1,49 @@
import http from 'http'; import http from 'http';
import dotenv from 'dotenv'
import path from 'path'
import express, { Request, Response } from 'express'; import express, { Request, Response } from 'express';
import bodyParser from 'body-parser' import bodyParser from 'body-parser'
import cookieParser from 'cookie-parser' import cookieParser from 'cookie-parser'
import session from 'express-session'
import redis from 'redis'
import connectRedis from 'connect-redis'
// import passport from 'passport'; // import passport from 'passport';
import register from '@react-ssr/express/register'; import register from '@react-ssr/express/register';
dotenv.config({ path: path.join(__dirname, '../.env') });
const SECRET = 'secret'
const RedisStore = connectRedis(session);
const redisClient = redis.createClient({
host: '127.0.0.1',
port: 6379,
password: process.env.REDIS_PASSWORD
})
redisClient.on('error', (error) => {
console.error(error);
});
redisClient.on('connect', () => {
console.log('Connection to Redis has been established successfully.');
});
const app = express(); const app = express();
app.set('trust proxy', 1); app.set('trust proxy', 1);
const server = http.createServer(app); const server = http.createServer(app);
app.use(bodyParser.json()); app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser()); app.use(cookieParser(SECRET));
app.use(
session({
store: new RedisStore({ client: redisClient }),
secret: SECRET,
resave: false,
saveUninitialized: false,
})
);
// initPassport(); // initPassport();
// app.use(passport.initialize()); // app.use(passport.initialize());

@ -0,0 +1,36 @@
#!/bin/sh
check_available() {
# Function to check if a program is installed
which $1 &> /dev/null
if [ $? = 1 ]; then
echo "$1 is not available, please install it before running the script"
exit 1
fi
}
gen_password() {
check_available openssl
openssl rand -base64 32
}
read -p "Redis password: (press enter to randomize): " redis_password
redis_password=${redis_password:-`gen_password`}
if [ ! -f "./.env" ]; then
echo "Copying ./env.example to ./.env"
cp ./env.example ./.env
fi
sed -i -e "s#REDIS_PASSWORD=.*#REDIS_PASSWORD=${redis_password}#g" \
"$(dirname "$0")/.env"
read -p "Start docker containers? (requires docker-compose) [Y/n] " start_docker
start_docker=${start_docker:-Y}
if [[ $start_docker =~ [yY] ]]; then
check_available docker-compose
sudo docker-compose up -d
fi
Loading…
Cancel
Save