I'm currently writing frontend app in Vue.js. Until I have a real web API, I've decided to use json-server. Now I'm trying to configure Vercel to start my json-server alongside Vue during deployment. Using concurrently "json-server --watch db.json" "npm run build
as override for build command results in json-server starting. However, build command reports npm run build exited with code 0
and then deployment continues to run until some timeout kills it. Nothing is deployed. How can I make it work? I don't need the json-server to be visible outside, just that my app can communicate with it on Vercel server.
edit:
just realized it's impossible to run it the way I've tried. Node will await json-server's closure, so deployment script will never finish, thus timeout.
What I'm trying to do now is to run json-server inside vue app, i.e. running something like this
import jsonServer from 'json-server';
const server = jsonServer.create();
const jsonRouter = jsonServer.router('db.json');
const middlewares = jsonServer.defaults();
server.use(middlewares);
server.use(jsonRouter);
server.listen(3000, () => {
console.log('JSON Server is running');
});
inside main.ts. The problem is I get error:
warning in ./node_modules/express/lib/view.js
Critical dependency: the request of a dependency is an expression
How can I fix that? Is it going to work, anyway?
edit2:
I ended up deploying separately to Heroku with script that runs only the json-server, and then using heroku url to act as pseudo-backend.