Skip to content

Commit

Permalink
Merge pull request #3 from Ahzem/signup-with-google
Browse files Browse the repository at this point in the history
Signup with google
  • Loading branch information
Ahzem authored Dec 16, 2024
2 parents 2ce2164 + ab02c95 commit 7f9cad4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"start": "node server/index.js",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
Expand Down
16 changes: 12 additions & 4 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,22 @@ import userRoutes from './routes/users.js';
// Environment setup
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
dotenv.config({ path: join(__dirname, '..', '.env') });

dotenv.config({ path: join(__dirname, '..', '.env') });
const app = express();
const PORT = process.env.PORT || 5000;

// Add production configuration
if (process.env.NODE_ENV === 'production') {
// Serve static files from the React app
app.use(express.static(join(__dirname, '../dist')));

// Handle React routing, return all requests to React app
app.get('*', (req, res) => {
res.sendFile(join(__dirname, '../dist', 'index.html'));
});
}

app.use(cors({
origin: process.env.CLIENT_URL,
credentials: true,
Expand All @@ -34,13 +45,11 @@ app.use(express.json());
app.use(helmet());
app.use(morgan('dev'));

// Routes
app.use('/api/auth', authRoutes);
app.use('/api/subscriptions', subscriptionRoutes);
app.use('/api/reminders', reminderRoutes);
app.use('/api/users', userRoutes);

// MongoDB connection
try {
await mongoose.connect(process.env.MONGODB_URI);
console.log('Connected to MongoDB successfully');
Expand All @@ -49,7 +58,6 @@ try {
process.exit(1);
}

// Start server
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
4 changes: 3 additions & 1 deletion src/services/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import axios from 'axios';
import { AuthResponse, NotificationPreferences, Subscription, SubscriptionInput, User } from '../types';

const BASE_URL = 'http://localhost:5000/api';
const BASE_URL = process.env.NODE_ENV === 'production'
? '/api' // In production, use relative path
: 'http://localhost:5000/api'; // In development, use local server

const api = axios.create({
baseURL: BASE_URL,
Expand Down
22 changes: 22 additions & 0 deletions staticwebapp.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"navigationFallback": {
"rewrite": "/index.html",
"exclude": ["/images/*", "/css/*", "/js/*", "/api/*"]
},
"routes": [
{
"route": "/api/*",
"allowedRoles": ["anonymous"]
},
{
"route": "/*",
"serve": "/index.html",
"statusCode": 200
}
],
"globalHeaders": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization"
}
}
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig({
global: 'globalThis',
'process.env': process.env
},
base: '/',
resolve: {
alias: {
'stream': 'stream-browserify',
Expand Down

0 comments on commit 7f9cad4

Please sign in to comment.