Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vue-router and Express

I've build a simple app using Vue.js and their vue-cli webpack.

I've used vue-router to control navigation around the site with the different views. This works fine when running locally.

I'm now wanting to deploy this onto Heroku, however the urls are no longer working. I've tried implementing middlewares, but have hit a brick wall!

I'm looking for something that might lead me along the right lines to configure node.js/express to run the app correctly.

Many thanks,

James

like image 386
James Clare Avatar asked May 28 '17 11:05

James Clare


People also ask

Can you use Express with Vue?

Combine Vue and ExpressCurrently Vue Client and Express server work independently on ports 8081 and 8080 . The first thing we need to do is to build Vue App for production.

Is express a router?

The express. Router() function is used to create a new router object. This function is used when you want to create a new router object in your program to handle requests.

What is express VueJS?

MEVN is the acronym for MongoDB, Express, VueJS, and Node. js as the full stack application. MongoDB is our data storage mechanism, Express is the middleware to handle HTTP requests and routing, VueJS is the client side JavaScript to render data, and Node. js is the server our application will run on.

What is router use Express?

The router. use() method has an optional mount path which is set to "/" by default. This method uses the specified middleware functions for this optional mountpath. The method is similar to app.


1 Answers

For those in a similar situation, now working using:

const express = require('express');
const history = require('connect-history-api-fallback');
const app = express();

const staticFileMiddleware = express.static(__dirname);
app.use(staticFileMiddleware);
app.use(history({
  disableDotRule: true,
  verbose: true
}));
app.use(staticFileMiddleware);

const port = 5555;
app.listen(port, () => {
  console.log(`Example app listening on port ${port}!`);
});

You can learn more about connect-history-api-fallback

like image 108
James Clare Avatar answered Sep 24 '22 08:09

James Clare