How to access my backend API

Asked

Viewed 78 times

0

I need to access my Node backend API to send emails with information from a contact form. I hosted my app on King Host and it appears this way o endereço da minha aplicação está mais ou menos assim the point is, since I’m a bit new to Node, I don’t know how to access my application remotely to route the forms I tried to use both addresses with the name of the route at the end example: urldomeusite.com:num-porta/contato and urldomeusite.com/meusite/contato and it didn’t work... this is my request:

const baseUrl = 'http://mywebsiteurl.com/contact'

const initialState = {
    message: {
        name: '',
        email: '',
        subject: '',
        main: ''
    },
}

export default class ContactUs extends Component {
    state = { ...initialState }

    reset = () =>{
        this.setState({message: initialState.message})
    }

    send = () => {

        const message = this.state.message
        const url = baseUrl
        console.log(message)
        axios.post(url, message)
            .then(this.reset())
            .then(alert('Message successfully sent!'))
    }

my index.js (backend)


const express = require('express')
const app = express()
const consign = require('consign')

const port = 4005

consign()
.then('./config/middlewares.js')
.then('./api')
.then('./config/routes.js')
.into(app)

app.listen(port, () => {
    console.log(port)
})

In middlewares.js I make the call to Cors

const bodyParser = require('body-parser')
const cors = require('cors')

module.exports = app => {
    app.use(bodyParser.json())
    app.use(cors())
}

If anyone can help me I’d really appreciate it!

  • Actually it should work without any port. But without code it is impossible to help friend! Edit your publication with code.

  • Okay, edited publication! =)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.