fazeel007 commited on
Commit
7127914
·
1 Parent(s): 8a11413

Remove Replit plugins from production build

Browse files

- Restrict Replit plugins to development + REPL_ID environment only
- This prevents Replit banner scripts from loading in production
- Fixes CSP violations for replit.com scripts in HF Spaces
- Keeps clean production builds without dev dependencies

Files changed (2) hide show
  1. server/index.ts +3 -1
  2. vite.config.ts +6 -6
server/index.ts CHANGED
@@ -49,7 +49,9 @@ app.use(helmet({
49
  contentSecurityPolicy: {
50
  directives: {
51
  defaultSrc: ["'self'"],
52
- scriptSrc: ["'self'", "'unsafe-inline'", "'unsafe-eval'"], // Allow for development
 
 
53
  styleSrc: ["'self'", "'unsafe-inline'"],
54
  imgSrc: ["'self'", "data:", "https:"],
55
  connectSrc: ["'self'", "https://api.studio.nebius.ai", "https://api.github.com"],
 
49
  contentSecurityPolicy: {
50
  directives: {
51
  defaultSrc: ["'self'"],
52
+ scriptSrc: process.env.NODE_ENV === 'production'
53
+ ? ["'self'", "'unsafe-inline'", "'unsafe-eval'"]
54
+ : ["'self'", "'unsafe-inline'", "'unsafe-eval'", "https://replit.com"], // Allow Replit in dev
55
  styleSrc: ["'self'", "'unsafe-inline'"],
56
  imgSrc: ["'self'", "data:", "https:"],
57
  connectSrc: ["'self'", "https://api.studio.nebius.ai", "https://api.github.com"],
vite.config.ts CHANGED
@@ -17,13 +17,13 @@ async function tryImport(moduleName: string, fallback = null) {
17
  export default defineConfig(async () => {
18
  const plugins = [react()];
19
 
20
- // Add Replit plugins only if available (for development)
21
- const runtimeErrorOverlay = await tryImport("@replit/vite-plugin-runtime-error-modal");
22
- if (runtimeErrorOverlay) {
23
- plugins.push(runtimeErrorOverlay.default());
24
- }
 
25
 
26
- if (process.env.NODE_ENV !== "production" && process.env.REPL_ID !== undefined) {
27
  const cartographer = await tryImport("@replit/vite-plugin-cartographer");
28
  if (cartographer) {
29
  plugins.push(cartographer.cartographer());
 
17
  export default defineConfig(async () => {
18
  const plugins = [react()];
19
 
20
+ // Add Replit plugins only in development and when running on Replit
21
+ if (process.env.NODE_ENV === "development" && process.env.REPL_ID !== undefined) {
22
+ const runtimeErrorOverlay = await tryImport("@replit/vite-plugin-runtime-error-modal");
23
+ if (runtimeErrorOverlay) {
24
+ plugins.push(runtimeErrorOverlay.default());
25
+ }
26
 
 
27
  const cartographer = await tryImport("@replit/vite-plugin-cartographer");
28
  if (cartographer) {
29
  plugins.push(cartographer.cartographer());