Heroku上的Nuxt返回404进行API调用,但在本地工作正常

时间:2019-10-18 12:53:18

标签: node.js vue.js heroku nuxt

任何对myapp.herokuapp.com/api/test的axios或邮递员调用都返回404,但是对localhost:3000/api/test的调用返回期望值。几个小时以来,我一直在努力应对,有什么问题吗?我的项目结构是这样的:

img

这是我的nuxt配置:

const pkg = require("./package");

module.exports = {
    mode: "universal",

    head: {
        title: "My app",
        meta: [
            { ...
            },
            { ...
            },
            { ...
            },
            { ...
            }
        ],
        link: [
            { ...
            },
            { ...
            },
            { ...
            }
        ],
        script: [ ...
        ]
    },

    /*
     ** Nuxt.js modules
     */
    modules: [
        [
            "@nuxtjs/axios",
            {
                baseURL: process.env.API_URL || "http://localhost:3000/"
            }
        ],
        "bootstrap-vue/nuxt",
    ],

    router: {
        scrollBehavior: async (to, from, savedPosition) => {
            if (savedPosition) {
                return savedPosition;
            }

            const findEl = async (hash, x) => {
                return ( ...
                );
            };

            if (to.hash) {
                let el = await findEl(to.hash);

                if (el) { ...
                }
            }

            return { ... };
        }
    },

    /*
     ** Build configuration
     */
    build: {
        optimization: { ... 
        },
        analyze: false
    }
};

我很乐意为此提供任何帮助,不确定从何处去。为什么在本地运行时应用程序访问api没问题,但是在heroku上时抛出404?我试图达到Postman可以想到的所有可能终点,但是没有任何效果。它仅在本地工作。

0 个答案:

没有答案