Skip to content

Commit

Permalink
Initial checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisrobison committed Nov 9, 2024
1 parent e82a152 commit 09c8a37
Show file tree
Hide file tree
Showing 32 changed files with 9,428 additions and 123 deletions.
1 change: 1 addition & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_API_URL=https://thegivehub.com/api
136 changes: 15 additions & 121 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,127 +4,21 @@ logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
.pnpm-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/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# 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 variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
node_modules
dist

# 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

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# 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

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# thegivehub
The Give Hub - Crowdfunding platform for social causes built on the Stellar blockchain
# React + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
38 changes: 38 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import js from '@eslint/js'
import globals from 'globals'
import react from 'eslint-plugin-react'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'

export default [
{ ignores: ['dist'] },
{
files: ['**/*.{js,jsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
sourceType: 'module',
},
},
settings: { react: { version: '18.3' } },
plugins: {
react,
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...js.configs.recommended.rules,
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
...reactHooks.configs.recommended.rules,
'react/jsx-no-target-blank': 'off',
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
]
170 changes: 170 additions & 0 deletions https.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
// vite.config.js
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import fs from 'fs'
import path from 'path'

export default defineConfig({
plugins: [react()],
server: {
host: '0.0.0.0',
port: 443, // Standard HTTPS port
strictPort: true,
https: {
key: fs.readFileSync('/etc/letsencrypt/live/11oclocktoast.com/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/11oclocktoast.com/fullchain.pem')
},
hmr: {
protocol: 'wss', // Use secure WebSocket for HMR
clientPort: 443
}
}
})

// To run the server with sudo (needed for port 443), create a start script
// start.sh
#!/bin/bash
```bash
#!/bin/bash

# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root (use sudo)"
exit 1
fi

# Set proper Node.js environment
export NODE_ENV=production

# Use the system's Node.js
NODE_PATH=$(which node)

# Get the actual user who invoked sudo
ACTUAL_USER=$(who am i | awk '{print $1}')
ACTUAL_HOME=$(getent passwd "$ACTUAL_USER" | cut -d: -f6)

# Use the actual user's npm configuration
export NPM_CONFIG_PREFIX="$ACTUAL_HOME/.npm-global"
export PATH="$NPM_CONFIG_PREFIX/bin:$PATH"

# Run Vite
cd /home/cdr/domains/thegivehub.com/frontend
$NODE_PATH /home/cdr/domains/thegivehub.com/frontend/node_modules/vite/bin/vite.js
```

Save this as a script and make it executable:
```bash
chmod +x start.sh
```

Now you can run:
```bash
sudo ./start.sh
```

To ensure your Node.js process can read the Let's Encrypt certificates:

```bash
# Add your user to the ssl-cert group
sudo usermod -a -G ssl-cert $USER

# Set proper permissions for the Let's Encrypt directory
sudo chmod -R g+rX /etc/letsencrypt/live/
sudo chmod -R g+rX /etc/letsencrypt/archive/

# You might need to log out and back in for the group changes to take effect
```

Alternative approach using a reverse proxy (recommended):

1. Install Nginx:
```bash
sudo apt update
sudo apt install nginx
```

2. Configure Nginx to proxy to Vite (running on a higher port):

```nginx
# /etc/nginx/sites-available/thegivehub.conf
server {
listen 443 ssl;
server_name 11oclocktoast.com;

ssl_certificate /etc/letsencrypt/live/11oclocktoast.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/11oclocktoast.com/privkey.pem;

# Modern SSL configuration
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;

# HSTS (uncomment if you're sure)
# add_header Strict-Transport-Security "max-age=63072000" always;

location / {
proxy_pass http://localhost:5173;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}

# WebSocket support for HMR
location /ws {
proxy_pass http://localhost:5173;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
}

# Don't forget HTTP to HTTPS redirect
server {
listen 80;
server_name 11oclocktoast.com;
return 301 https://$server_name$request_uri;
}
```

3. Enable the site:
```bash
sudo ln -s /etc/nginx/sites-available/thegivehub.conf /etc/nginx/sites-enabled/
sudo nginx -t # Test the configuration
sudo systemctl restart nginx
```

4. Update Vite config to run on a regular port:
```javascript
// vite.config.js
export default defineConfig({
plugins: [react()],
server: {
host: '0.0.0.0',
port: 5173,
strictPort: true,
hmr: {
// HMR configuration for working through Nginx
host: '11oclocktoast.com',
protocol: 'wss',
clientPort: 443
}
}
})
```

The Nginx approach is recommended because:
1. Better security (no need to run Node as root)
2. Better performance (static file serving)
3. Easier certificate management
4. Built-in HTTP to HTTPS redirect
5. Ability to add other security headers
6. Better WebSocket handling for HMR

Would you like me to:
1. Add more security headers to Nginx?
2. Set up automatic certificate renewal?
3. Configure development vs production settings?
4. Add error pages and logging?
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
Loading

0 comments on commit 09c8a37

Please sign in to comment.