Statically served vue-router app by Flask shows 404 for custom pages on Heroku - vue.js

I've gone through several Stack Overflow pages and the official Vue guide, but my app still returns 404 results when going to a different page.
The structure of my app looks like this, with a client folder that has the Vue app and a server folder containing app.py that statically serves the index.html in the client/dist folder through Flask.
Contents of static.json are as outlined in the guide:
{
"root": "client/dist",
"clean_urls": true,
"routes": {
"/**": "index.html"
}
}
with just modified root folder to go to client/dist. Running the app locally with npm run serve works, as does opening it up on its Heroku page and clicking on the nav. However, directly going to a page, such as /translate, always returns 404.
I have installed the following buildpacks:
=== readiglot Buildpack URLs
1. heroku/nodejs
2. heroku/python
3. https://github.com/heroku/heroku-buildpack-static
The app is hosted here: https://www.readiglot.herokuapp.com.
On npm run build from the root directory, the dist folder is built by Heroku in the client folder.
Am I missing something? Could anyone advise as to additional configuration?

The answer is in the app.py file - you need to statically serve the file using a catch all route.
#app.route("/", defaults={"path": ""})
#app.route("/<string:path>")
#app.route("/<path:path>")
def index(path):
return app.send_static_file("index.html")
By putting the serve_static_file in the Flask app to redirect from all other routes, 404 only shows up on a true 404.

Related

Deploying VUE Js Application to Heroku issues (404 not found - blank page after deploy)

I am having a hard time getting my app to come up on Heroku after deploying a VUE JS application. It keeps giving me a Not Found page (even when everything builds)
After looking over a lot of suggestions on Stack Overflow and videos, I finally figured it out. The first think you want to do is go to the command line and type: Heroku Logs, when I did this, I saw this:
Error: ENOENT: no such file or directory, stat '/app/client/build/index.html'
After some research, I found out that when the vue cli builds, it places it assets in a folder called 'dist" and not build. In my server.js file, I just changed my entry to
if(process.env.NODE_ENV === 'production')
{
//Set static folder (our public folder)
app.use(express.static('client/dist'));
app.get('*',(req,res) => {
res.sendFile(path.resolve(__dirname,'client','dist','index.html'));
})
}
It "used to have" 'build' in it, 'build' is actually used if you are deploying a "React" application (which have done on a previous build). After I changed this to 'dis', MY APP CAME UP .. !!! YAHHHHH!!!

Deploying vite vue.js app with vue router to GitHub Pages with search engines support

I am deploying my website powered by vue vith vue-router(history mode) to gituhb pages using vite builder.
So I got a problem: Github Pages is returning 404 error each time I reloading the page with non-root path.
Adding cp dist/index.html dist/404.html seems like solution. The page is displaying correctly but GitHub is returning 404 status. And this is an important problem because search engines skipping paths in my sitemap.xml that returns 404 status code. That is, all non-root paths.

express static with multiple routes returning 404

I'm serving up two create-react apps.
This works navigating to localhost:9000/
app.use('/', express.static(path.join(__dirname, APP_STATIC_PATH)));
But this doesn't work when I navigate to localhost:9000/app
app.use('/app', express.static(path.join(__dirname, APP_STATIC_PATH)));
I get a bunch of net::ERR_ABORTED 404 (Not Found) for all my .css and .js files
How can I change the create react app public url to point to the correct static dic?
In case anyone's running into the same problem.
In package.json you can set your homepage:'/app' and create react-app will use that on yarn build.

Deployed Vue app managed with 'webpack-simple' doesn't work

I'm working on my first Vue app, which uses the Moment library and Firebase (if that matters). I use default Webpack simple. To deploy the app I did npm run build.
But when opening directly index.html (the app is deployed here) I get "Failed to load resource: the server responded with a status of 404 (Not Found)" error message and the app doesn't work at all as a result.
I have no idea how to troubleshoot this issue since there's no more information that this in DevTools...
Any idea about what I can do next?
App source code
Remove the first forward slashes of all your assets path.
It should fix your problem.
<script src="/dist/build.js"></script> // No!
<script src="dist/build.js"></script> // Yes!
Vue adds it by default during the build process, in order to make your assets relative to the root folder.

angular 2 router index.html sharepoint

I have a angular 2 SPA running from within a SharePoint 2010 document library. However, I have a problem with routing. When I start the application by running "index.html", the link in the browser shortly displays:
<server>/scripts/angular_app/index.html
When the application is loaded it changes to:
<server>/scripts/angular_app/#/information-system
'information-system' is the default route of my application.
So far, so good.
If I do a reload of the page now, SharePoint loads its default view:
<server>/scripts/angular_app/Forms/AllItems.aspx
This is because the routing removes the 'Index.html' from the url and SharePoint loads the default which is 'AllItems.aspx' and not 'index.html'.
Is there any way of telling the angular 2 routing system to leave the 'index.html' bit in the url?
Thanks for any help!
Joachim
I added following line to index.html to keep index.html in the URL all the time:
<base href="/index.html">
I solved my issue by extending the base href with the filename at compile time:
ng build --dev --bh /scripts/filingangular/index.html
I was not aware that you could put an actual filename here.