0

I have done the following sample: https://www.youtube.com/watch?v=9Kju3DovLrg and something is broken my connections.

I can only see this error in my browser:

GET http://localhost:8080/api/pedidos 404 (Not Found)

My only one modification was to change the table to add one more column.

My server.js

var express = require("express")
var bodyParser = require("body-parser")

var pedidos = require("./routes/pedidos")
var cors = require("cors")

var port = 3000

var app = express()
app.use(cors())

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))

app.use("/api", pedidos)

app.listen(port, function () {
    console.log('Server started on port >>> ' + port)
})

My dev webpack config:

module.exports = {
  dev: {

    // Paths
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',

    // Various Dev Server settings
    host: 'localhost', // can be overwritten by process.env.HOST
    port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    proxyTable: {
      '/api': {
        target: 'http://localhost:3000',
        changeOrigin: true,
        logLevel: 'debug'
      }
    },
    autoOpenBrowser: false,
    errorOverlay: true,
    notifyOnErrors: true,
    poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-

  }

My pedidos.js

var express = require("express")
var router = express.Router()
const Pedido = require("../model/Pedido")

//Get All pedidos
router.get("/pedidos", (req, res) => {
    Pedido.findAll()
        .then(pedidos => {
            res.json(pedidos)
        })
        .catch(err => {
            res.send("error: " + err)
        })
})

module.exports = router
4
  • Paste pedidos routes as well. Commented Mar 22, 2019 at 10:01
  • 1
    port = 3000 but //localhost:8080/api/pedidos has 8080 ? Commented Mar 22, 2019 at 10:07
  • app.use("/api", pedidos) , show us the code for the route specifically. Also check if your route accepts the new mysql schema properly. Commented Mar 22, 2019 at 10:07
  • I've added pedidos.js from routes Commented Mar 22, 2019 at 10:10

1 Answer 1

1

Did you restart the frontend server,vue.config.js change need restart by runing 'yarn serve'

Sign up to request clarification or add additional context in comments.

3 Comments

How is your vue-project created? I watch the video that you post. It look like created with vue-cli 2.x! You need use the same version
It looks like I needed a vue files config reboot after some test times with difference proxyTable settings ¬¬'
Yes! It cannot auto reboot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.