Error with ports: vue.js+node.js project in heroku

前端 未结 1 1838
我在风中等你
我在风中等你 2021-01-16 21:01

Trying to deploy my fullstack project. Locally it builds and working well, but in Heroku, after \'git push heroku master\' command and automatic build after it I get the ap

相关标签:
1条回答
  • 2021-01-16 21:35

    You need to add a server.js file with express and the entry route on the root foolder of you app (in the same folder where package.json/index.html is located) . I have a vue app on heroku as well, it's not very hard.

    // server.js
    const express = require('express')
    const path = require('path')
    const history = require('connect-history-api-fallback')
    
    const app = express()
    
    const staticFileMiddleware = express.static(path.join(__dirname + '/dist'))
    
    app.use(staticFileMiddleware)
    app.use(history({
      disableDotRule: true,
      verbose: true
    }))
    app.use(staticFileMiddleware)
    
    app.get('/', function (req, res) {
      res.render(path.join(__dirname + '/dist/index.html'))
    })
    
    var server = app.listen(process.env.PORT || 8080, function () {
      var port = server.address().port
      console.log('App now running on port', port)
    })
    
    0 讨论(0)
提交回复
热议问题