Skip to content

Instantly share code, notes, and snippets.

View Gaurav8757's full-sized avatar
🏠
Working from home

Gaurav Kumar Gaurav8757

🏠
Working from home
View GitHub Profile
@Gaurav8757
Gaurav8757 / CompLoader.js
Created May 21, 2024 16:35
Company Name Loader
const TextLoader = () => {
return (
<div className="flex justify-center items-center bg-gray-100">
<div className="relative flex space-x-1 text-xl font-bold text-gray-800">
{[...'ELEEDOMIMF'].map((char, index) => (
<span
key={index}
className="animate-bounce bg-gradient-to-r from-stone-900 to-red-600 bg-clip-text text-transparent rounded-full"
style={{ animationDelay: `${index * 0.1}s` }}
>
@Gaurav8757
Gaurav8757 / pass_props.js
Last active May 22, 2024 07:11
Solve problem from application error or Uncaught Error: A component suspended while responding to synchronous input.
<TableData filteredData = {filteredData} onUpdateInsurance={onUpdateInsurance} onDeleteAllData ={onDeleteAllData} totalItems = {totalItems} />
import React from 'react';
import UpdateMaster from './UpdateMaster';
const InsuranceTable = ({ filteredData, onUpdateInsurance, onDeleteAllData, totalItems }) => {
return (
<div className="inline-block min-w-full w-full py-0 relative">
<table className="min-w-full text-center text-sm font-light table border border-black">
<thead className="border-b font-medium bg-slate-300 sticky top-16">
@Gaurav8757
Gaurav8757 / env.js
Created May 20, 2024 10:53
ES6 .ENV code
import dotenv from "dotenv";
dotenv.config();
const {CORS, CORS1, CORSLOCAL} = process.env;
const corsOptions = {
origin: [CORS, CORS1, CORSLOCAL], // Specify trusted domains
methods: ['GET', 'POST'], // Specify allowed methods
allowedHeaders: ['Content-Type', 'Authorization'] // Specify allowed headers
};
app.use(cors(corsOptions));
@Gaurav8757
Gaurav8757 / preflight.js
Last active May 20, 2024 10:55
#Handling Preflight Requests Manually in Express index.js
import cors from "cors"
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "https://example.com"); // Change to your domain
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
// Handle preflight requests
if (req.method === 'OPTIONS') {
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH");
return res.status(204).end();
}
@Gaurav8757
Gaurav8757 / cors.js
Last active May 20, 2024 10:55
This setup is more secure and flexible, allowing you to specify the origins, methods, and headers that are permitted.
// Use the cors middleware with specific options
app.use(cors({
origin: 'https://example.com', // Specify the allowed origin
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', // Specify the allowed methods
allowedHeaders: 'Content-Type,Authorization' // Specify the allowed headers
}));
# Multiple Selected User Can Access
const corsOptions = {