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
- server/index.ts +3 -1
- 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:
|
|
|
|
|
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
|
21 |
-
|
22 |
-
|
23 |
-
|
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());
|