I want to build a single page application with Vue.js using Nginx as my webserver and a my own Dropwiward REST API. Moreover I use Axios to call my REST request.
My nginx config looks like
server { listen 80; server_name localhost; location / { root path/to/vue.js/Project; index index.html index.htm; include /etc/nginx/mime.types; } location /api/ { rewrite ^/api^/ /$1 break; proxy_pass http://localhost:8080/; } }
Currently I can just call my localhost/api/path/to/rescource
to get the the information from the backend.
I build the Front end with HTML and javascript(vue.js) which has worked so far. However when I want to build a single page application most tutorials mention node.js. How can I use Nginx instead?
Open in browser To view the project, open a tab and type http://localhost:3000 into the URL bar. That's the address that the Node server is listening to. You should now see this page, which is the basic structure of our project.
Add the following code to your Nginx Config:
location / { try_files $uri $uri/ /index.html; }
the following snippet has been taken from vue-router docs, which is here.
Also, you need to enable history mode on VueRouter:
const router = new VueRouter({ mode: 'history', routes: [...] })
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