I am trying to deploy my react application on vercel .But i want to run my build using node server. Because I have to use prerender.io in my node app. Such that preview can come with dynamic value when someone share the link.
因为我要在我的根文件夹中添加服务器. js, 这就是代码 :
const express = require( express );
const prerender = require( prerender-node );
const app = express();
// Serve the static React build files
app.use(express.static( build ));
// Use prerender.io for prerendering
app.use(prerender.set( prerenderToken , MY TOKEN ));
// Serve the React app for all routes
app.get( * , (req, res) => {
res.sendFile(path.resolve(__dirname, build , index.html ));
});
// Start the server
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});
这是我的动脉,json:
{
"rewrites": [
{ "source": "/(.*)", "destination": "/server.js" }
]
}
但我的建筑不是通过节点读取,
But when i added api folder in my app and added same server.js code there , afterwards it started running through node app. And i dont want to use /api in my url for it to work. So what can i walk around such that my build runs through node app .
这些是我包裹里的剧本,杰森
"scripts": {
"start": "node server.js",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},```