In my case, I needed to use the same base URL to load both the page request and the assets that are included in each page.
Requests:
GET: mywebsite.com/customer/favorites \- GET: mywebsite.com/assets/images/logo.svg \- GET: mywebsite.com/assets/css/bootstrap.min.css \- GET: mywebsite.com/modules/shared/web-components/item-list.js
Files structure:
public \- assets \- images \- css \- modules \- admin \- customer \- shared server.js package.json
So, I wrote a vercel.json file that takes all the request URLs without file extensions and pass them to the server.js file, while the request URLs that have a file extension (like .css, .js, .img) are taken as static calls to the public directory
vercel.json
server.js
.css, .js, .img
{ "name": "express-static-website", "version": 2, "public": true, "builds": [ { "src": "server.js", "use": "@vercel/node" }, { "src": "public/**", "use": "@vercel/static" } ], "routes": [ { "src": "/((?!.*\\.\\w+$).*)", "dest": "/server.js" }, { "src": "/(.+\\.[a-z]+)$", "dest": "/public/$1" } ] }
I tried to apply the same settings with other src regex and struggled a lot but nothing worked till I tried your solution.
Thank You, so much bro 🙏
I'm happy it helped you :)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In my case, I needed to use the same base URL to load both the page request and the assets that are included in each page.
Requests:
Files structure:
So, I wrote a
vercel.jsonfile that takes all the request URLs without file extensions and pass them to theserver.jsfile, while the request URLs that have a file extension (like.css, .js, .img) are taken as static calls to the public directoryI tried to apply the same settings with other src regex and struggled a lot but nothing worked till I tried your solution.
Thank You, so much bro 🙏
I'm happy it helped you :)