0

I had problems yesterday that I never had on previous nuxt projects about CORS.

I have indeed read that it was necessary to set the proxy to solve the problem. Despite this, I have a 504 error. I followed several solutions found on the github repository & stack overflow without having found the problem.

My post function

await this.$axios.post("/api/contact", {
replyTo: this.form.email,
name: this.form.name,
firstName: this.form.firstName,
phone: this.form.phone,
company: "",
message: this.form.message,}).then(() => {this.isSend = true;}).catch((e) => {console.log(e);this.isError = true;});

my nuxt config

modules: ["@nuxtjs/axios", "@nuxtjs/proxy"],
axios: {
    proxy: true,
    debug: true,
},
proxy: {
    "/api/": {
        target: "http://myserver.eu-west-3.elasticbeanstalk.com/",
        pathRewrite: { "^/api/": "" },
        changeOrigin: true,
    },
},

my api call need to be done on http://myserver.eu-west-3.elasticbeanstalk.com/contact

I'm pretty sure I made a mistake somewhere, but I really can't find where... error504 Initial cors error

EDIT 1 : everything work find with postman, but not with my frontend i tried with a apigateway lambda ses, it's work with postman, not with front end, i tried with a node express server with ses, it's work with lambda, not with front end :(

EDIT 2 : I managed to make the form submission work, I cloned one of my old projects, then I replaced the content with that of this project. I think it's a nuxtJs and Axios problem. Very strange.

Max
  • 1
  • 1
  • It's not confirmed that cors and 504 are related. – Estus Flask Jul 13 '22 at 10:33
  • Try that one: https://stackoverflow.com/a/72211930/8816585 – kissu Jul 13 '22 at 12:10
  • Sure, i edited and add the error that i got first with a more simple configuration that work for me earlier in every projects ;) https://i.stack.imgur.com/BU4eP.png – Max Jul 13 '22 at 12:10
  • I already tried this @kissu :/ everything work find with postman, but not with my frontend – Max Jul 13 '22 at 12:26
  • This is pretty much what I have written there (Postman doesn't have CORS). So, if it's working with Postman, it is still not fine. – kissu Jul 13 '22 at 12:32
  • I understand better, thank you. My server has the cors package configured and allows all origins. I don't understand why nuxt is blocking requests. It seems that pre-flight requests are responsible... – Max Jul 13 '22 at 13:02

0 Answers0