Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to load resource: the server responded with a status of 404 () on Railway #155

Closed
masrur-mmrs opened this issue Apr 2, 2024 · 1 comment

Comments

@masrur-mmrs
Copy link

When trying to deploy my medusa admin backend on Railway, the dashboard doesn't load. It works on local development. But the issue seems to persist when deployed. I'm only able to recreate this on localdev when I set autoRebuild: false on first medusa start after a clean build. But if I set autoRebuild: true after the first build and then start the backend the following starts work properly even if I set autoRebuild: false afterwards. But when I push changes and a new deployment starts, all I get is this:

Screenshot 2024-04-03 at 4 25 38 AM

The console log prints:

Refused to apply style from 'https://aesthetix-backend.up.railway.app/assets/index-9853bef1.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
index-d61dff85.js:1 

Failed to load resource: the server responded with a status of 404 ()app:1 

Refused to apply style from 'https://aesthetix-backend.up.railway.app/assets/index-9853bef1.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

And here's the backend log, no indication of anything wrong here tho:

Server is ready on port: 9000

::ffff:10.10.10.12 - - [02/Apr/2024:22:08:16 +0000] "GET /health HTTP/1.1" 200 2 "-" "Go-http-client/1.1"

103.91.128.224 - - [02/Apr/2024:22:17:49 +0000] "GET / HTTP/1.1" 404 139 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"

103.91.128.224 - - [02/Apr/2024:22:17:51 +0000] "GET /app HTTP/1.1" 200 446 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"

103.91.128.224 - - [02/Apr/2024:22:17:51 +0000] "GET /assets/index-9853bef1.css HTTP/1.1" 404 164 "[https://aesthetix-backend.up.railway.app/app"](https://aesthetix-backend.up.railway.app/app%22); "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"

103.91.128.224 - - [02/Apr/2024:22:17:51 +0000] "GET /assets/index-d61dff85.js HTTP/1.1" 404 163 "[https://aesthetix-backend.up.railway.app/app"](https://aesthetix-backend.up.railway.app/app%22); "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"

103.91.128.224 - - [02/Apr/2024:22:17:53 +0000] "GET /assets/index-9853bef1.css HTTP/1.1" 404 164 "[https://aesthetix-backend.up.railway.app/app"](https://aesthetix-backend.up.railway.app/app%22); "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"

And here's my medusa-config.js:

const dotenv = require("dotenv");

let ENV_FILE_NAME = "";
switch (process.env.NODE_ENV) {
    case "production":
        ENV_FILE_NAME = ".env.production";
        break;
    case "staging":
        ENV_FILE_NAME = ".env.staging";
        break;
    case "test":
        ENV_FILE_NAME = ".env.test";
        break;
    case "development":
    default:
        ENV_FILE_NAME = ".env";
        break;
}

try {
    dotenv.config({ path: process.cwd() + "/" + ENV_FILE_NAME });
} catch (e) {}

// CORS when consuming Medusa from admin
const ADMIN_CORS =
    process.env.ADMIN_CORS || "http://localhost:7000,http://localhost:7001";

// CORS to avoid issues when consuming Medusa from a client
const STORE_CORS = process.env.STORE_CORS;
// || "http://localhost:8000";

const DATABASE_URL =
    process.env.DATABASE_URL || "postgres://localhost/medusa-starter-default";

const REDIS_URL = process.env.REDIS_URL || "redis://localhost:6379";

const BACKEND_URL = process.env.BACKEND_URL


const WORKER_MODE = process.env.MEDUSA_WORKER_MODE

const STRIPE_API_KEY = process.env.STRIPE_API_KEY;
const STRIPE_WEBHOOK_SECRET = process.env.STRIPE_WEBHOOK_SECRET;

const plugins = [
    `medusa-fulfillment-manual`,
    `medusa-payment-manual`,
    {
        resolve: `medusa-payment-stripe`,
        options: {
            api_key: STRIPE_API_KEY,
            webhook_secret: STRIPE_WEBHOOK_SECRET,
        }
    },
    {
        resolve: `medusa-file-s3`,
        options: {
            s3_url: process.env.S3_URL,
            bucket: process.env.S3_BUCKET,
            region: process.env.S3_REGION,
            access_key_id: process.env.S3_ACCESS_KEY_ID,
            secret_access_key: process.env.S3_SECRET_ACCESS_KEY,
        },
    },
    {
        resolve: "@medusajs/admin",
        /** @type {import('@medusajs/admin').PluginOptions} */
        options: {
            autoRebuild: false,
        }
    },
    {
        resolve: `medusa-plugin-algolia`,
        options: {
            applicationId: process.env.ALGOLIA_APP_ID,
            adminApiKey: process.env.ALGOLIA_ADMIN_API_KEY,
            settings: {
                indexName: {
                    indexSettings: {
                        searchableAttributes: ["title", "description"],
                        attributesToRetrieve: [
                            "id",
                            "title",
                            "description",
                            "handle",
                            "thumbnail",
                            // "variants",
                            "variant_sku",
                            "options",
                            "collection_title",
                            "collection_handle",
                            "images",
                        ],

                    },
                    transformer: (product) => ({
                        objectID: product.id,
                        // other attributes...
                    }),
                },
            },
        },
    },
    {
        resolve: `medusa-plugin-sendgrid`,
        options: {
            api_key: process.env.SENDGRID_API_KEY,
            from: process.env.SENDGRID_FROM,
            order_placed_template: process.env.SENDGRID_ORDER_PLACED_ID,
        },
    },
];

/** @type {import('@medusajs/medusa').ConfigModule["featureFlags"]} */
const featureFlags = {
    product_categories: true,
    order_editing: true,
};

/** @type {import('@medusajs/medusa').ConfigModule["modules"]} */
const modules = {
    cacheService: {
        resolve: "@medusajs/cache-redis",
        options: {
            redisUrl: process.env.CACHE_REDIS_URL,
            ttl: 60 * 60,
        }
    },
    eventBus: {
        resolve: "@medusajs/event-bus-redis",
        options: {
            redisUrl: process.env.EVENTS_REDIS_URL,
        },
    },
};


/** @type {import('@medusajs/medusa').ConfigModule["projectConfig"]} */
const projectConfig = {
    jwtSecret: process.env.JWT_SECRET,
    cookieSecret: process.env.COOKIE_SECRET,
    store_cors: STORE_CORS,
    database_url: DATABASE_URL,
    admin_cors: ADMIN_CORS,
    jobs_batch_size: 100,
    worker_mode: WORKER_MODE,
    // Uncomment the following lines to enable REDIS
    redis_url: REDIS_URL,
    http_compression: {
        enabled: true,
        level: 6,
        memLevel: 8,
        threshold: 1024,
    },
    // database_extra: process.env.NODE_ENV !== "development" ? {
    //     ssl: {
    //         rejectUnauthorized: false,
    //     },
    // } : {},
};

/** @type {import('@medusajs/medusa').ConfigModule} */
module.exports = {
    projectConfig,
    plugins,
    modules,
    featureFlags,
};

I figured it might have something to do with railway looking in the wrong directory for static assets so I tried changing index.js to include

app.use(express.static(path.join(__dirname, 'build')));

            app.get('*', (req, res) => {
                res.sendFile(path.join(__dirname, 'build', 'index.html'));
            });

still no luck, so I changed the nixpacks.toml to include

[static]
dir = ['build']

Also no luck.

Can anyone please help me? This problem seems to come and go on its own every now and then, not so much on localdev as much as with deployment.

Here are my network request headers:
Screenshot 2024-04-03 at 4 44 39 AM
Screenshot 2024-04-03 at 4 45 07 AM

@masrur-mmrs
Copy link
Author

This can be fixed by adding path: 'public' in admin options in medusa-config.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant