-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e82a152
commit 09c8a37
Showing
32 changed files
with
9,428 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VITE_API_URL=https://thegivehub.com/api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }, | ||
], | ||
}, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.