Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于提供Vue.js html文件的express server_Express_Heroku_Vue.js - Fatal编程技术网

用于提供Vue.js html文件的express server

用于提供Vue.js html文件的express server,express,heroku,vue.js,Express,Heroku,Vue.js,我使用CLI编写了一个Vue应用程序。我已经运行了build命令,得到了dist文件夹和html文件以及相关的js/css文件等。现在我想用node/express服务器在heroku上托管这个应用程序,我只写了一半 作为记录,我使用vue路由器在不同的路径上渲染不同的组件 const routes = [ {path: "/", redirect: "/home"}, {path: "/home", component: body}, {path: "/home/new", com

我使用CLI编写了一个Vue应用程序。我已经运行了build命令,得到了dist文件夹和html文件以及相关的js/css文件等。现在我想用node/express服务器在heroku上托管这个应用程序,我只写了一半

作为记录,我使用vue路由器在不同的路径上渲染不同的组件

const routes = [
  {path: "/", redirect: "/home"},
  {path: "/home", component: body},
  {path: "/home/new", component: create},
  {path: "/home/entry/:id", component: blog},
  {path: "/register", component: register},
  {path: "/logout", component: logout},
  {path: "/home/user/:userprofile", component: userprofile}

]
我的vue应用程序为其所有数据调用一个单独的后端API,因此我请求的express server仅用于跨所有路由为html文件提供服务器

这是我从谷歌找到的:

var express = require('express');
var path = require('path');
var serveStatic = require('serve-static');
var port = process.env.PORT || 5000;

app = express();

app.use(serveStatic(__dirname + "/dist"));

app.listen(port);
当我去“/”路线时它工作,但当我去“/家”或类似的地方时,它返回一个错误“不能去/家”或类似的地方


有人能给我写一个简短的express server应用程序,用于在Heroku上部署vue吗?

很可能您的web服务器上缺少将所有请求重定向到“/”的配置。VueJs路由器在此之后负责,但除非您明确配置web服务器,否则它不会接收请求


是一个Vue路由器文档页,其中包含不同web服务器的简短代码段,您需要将其添加到web服务器配置中。

您使用的是历史模式还是哈希模式?@LassiUosukainen我使用的是历史模式,用于根据路由更改呈现组件。我知道您是对的,我正在部署一个不同的服务器文件,但没有匹配的路由模式来服务该文件。我简直不敢相信我花了一个小时搔搔头却忽略了这一点。谢谢你的帮助。