Serving VueJS Builds via Express.js using history mode

前端 未结 2 1049
囚心锁ツ
囚心锁ツ 2020-12-05 16:59

I want to serve vue js dist/ via express js. I am using history router in vue js app.

The following are the api calls

  1. api/
  2. s-file
2条回答
  •  遥遥无期
    2020-12-05 17:27

    The very simpler one if anyone wants to use

    Just add this below all the valid routes and above app.listen

    app.all("*", (_req, res) => {
      try {
        res.sendFile('/absolute/path/to/index.html');
      } catch (error) {
        res.json({ success: false, message: "Something went wrong" });
      }
    });
    

    Make sure you have included

    app.use(express.static('/path/to/dist/directory'));
    

提交回复
热议问题