title: Serving VueJS Builds via Express.js using history mode
body: <p>I want to serve vue js <code>dist/</code> via express js. I am using history router in vue js app.</p>
  
  <p>The following are the api calls</p>
  
  <ol>
  <li>api/</li>
  <li>s-file/sending/:id</li>
  <li>terms/get/:which </li>
  </ol>
  
  <p>As i have figured out a solution in python <a href="https://gist.github.com/tbhaxor/ce735c07fd312e1605c79998fd3d8c30" rel="nofollow noreferrer" title="github">here</a>. I don't know how to do it in node js with <code>express</code></p>
  
  <p>The code i am using right now is</p>
  
  <pre><code>app.use(function (req, res, next) {
      if (/api/.test(req.url))
          next();
      else {
          var file = "";
          if (req.url.endsWith(".js")) {
              file = path.resolve(path.join(distPath, req.url))
              res.header("Content-Type", "application/javascript; charset=utf-8");
              res.status(200);
              res.send(fs.readFileSync(file).toString());
          } else if (req.url.endsWith(".css")) {
              file = path.resolve(path.join(distPath, req.url))
              res.header("Content-Type", "text/css; charset=utf-8");
              res.status(200);
              res.send(fs.readFileSync(file).toString());
  
          } else {
              file = path.resolve(path.join(distPath, "index.html"))
              res.header("Content-Type", "text/html; charset=utf-8");
              res.status(200);
              res.send(fs.readFileSync(file).toString());
          }
  
      }
  })
  </code></pre>