April 2020
Intermediate to advanced
716 pages
18h 55m
English
In order to implement the API that will render the VR game in the browser, we will add a route in the backend that will receive a GET request and open the index.html page from React 360.
This route will be declared in game.routes.js with the other game routes, as follows:
mern-vrgame/server/routes/game.routes.js:
router.route('/game/play') .get(gameCtrl.playGame)
A GET request received at this route will execute the playGame controller method, which will return the index.html page in response to the incoming request. The playGame controller method will be defined as shown in the following code:
mern-vrgame/server/controllers/game.controller.js:
const playGame = (req, res) => { res.sendFile(process.cwd()+'/server/vr/index.html') ...Read now
Unlock full access