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

assetPrefix not working in Production #4799

Closed
lucasnorman opened this issue Jul 18, 2018 · 5 comments
Closed

assetPrefix not working in Production #4799

lucasnorman opened this issue Jul 18, 2018 · 5 comments

Comments

@lucasnorman
Copy link

lucasnorman commented Jul 18, 2018

Bug report

Describe the bug

assetPrefix is not being appended to _next file routes in production. Works when not in production.

next config:

const withTypescript = require("@zeit/next-typescript");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
// const { PHASE_DEVELOPMENT_SERVER } = require("next/constants");

const isProd = process.env.NODE_ENV === 'production'
module.exports = withTypescript({
    assetPrefix: isProd ? 'auth' : '',
    webpack(config, options) {
        // Put type errors in console
        if (options.isServer)
            config.plugins.push(new ForkTsCheckerWebpackPlugin());

        return config;
    },
});

server config:

...
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });

const handle = app.getRequestHandler();

app.prepare().then(() => {
    const server = express();

    server.use(cors()); // enable `cors` to set HTTP response header: Access-Control-Allow-Origin: *

    server.use(
        "/auth/api/v1",
        bodyParser.json({ limit: "50mb" }),
        graphqlExpress({ schema, rootValue: "/" }),
    );

    server.use("/graphiql", graphiqlExpress({ endpointURL: "/auth/api/v1" }));

    server.use("/auth", handle);

    server.set("port", port);

    server.get("*", (req, res) => {
        return handle(req, res);
    });

    server.listen(server.get("port"), () => {
        console.log(`Currently running ${url}:${port}`);
        logger.log("info", `Server started on ${url}:${port}`);
    });
});

Expected behavior

Append assetPrefix to _next files routes.

Screenshots

screen shot 2018-07-18 at 1 20 52 pm

System information

  • Dev: Mac, Production: Ubuntu
  • Chrome
  • Version of Next.js: [6.0.3]

Additional context

I have tried setting the assetPrefix unconditionally in my next config and again, it works in dev but not production.

@timneutkens
Copy link
Member

Should work fine, we have zeit.co/docs nextjs.org/learn both using assetPrefix in production. Also, Next.js has integration tests for assetPrefix, so I wonder if you could provide a minimal example in a GitHub repository

@lucasnorman
Copy link
Author

lucasnorman commented Jul 18, 2018

Hmm the code base I am working on is very large and I have a feeling it is going to take me a very long time to reproduce this issue, even minimally. A lot of config has gone into this. I am setting assetPrefix in my next config and then reference the path in my server config. Anything else I need to do??

In my build files, is there somewhere I can look to debug this? I checked my files in production, which are inside a k8s pod, and it looks like the server file got compiled correctly, however, I am not sure if there is anywhere else I can look..

@timneutkens
Copy link
Member

I'm not sure why reproducing this would be hard 🤔 just yarn create next-app reproduction cd reproduction, add your custom server, add next.config.js

If that works fine then it's something in your app and we can talk about further debugging of your actual app, as then it's something specific to your setup.

Just making sure we don't spend a lot of time investigating something together that isn't broken without verifying the core functionality is ok 😄

@lucasnorman
Copy link
Author

You are right. I did a bit of investigating and found it is not the build process... It looks like it has something to do with kubernetes or the ingress on my cluster. Im not sure what is happening though. This can be closed as it is not a bug. Sorry for the inconvenience and thanks for your help!

@timneutkens
Copy link
Member

Interesting, feel free to reach out on spectrum.chat/next-js / dm me if you're stuck 👍

@lock lock bot locked as resolved and limited conversation to collaborators Jul 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants