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
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With