Playing the VR game
Users on MERN VR Game will be able to open and play any of the games from within the application. To enable this, we will set up a route on the server that renders index.html
, which was generated with React 360, in the response to a GET request at the following path:
/game/play?id=<game ID>
The path takes a game ID value as a query
parameter, which is used in the React 360 code to fetch the game details with the read API.
API to render the VR game view
The GET request to open the React 360 index.html
page will be declared in game.routes.js
, as follows.
mern-vrgame/server/routes/game.routes.js
:
router.route('/game/play') .get(gameCtrl.playGame)
This will execute the playGame
controller method to return the index.html
page in response to the incoming request.
mern-vrgame/server/controllers/game.controller.js
:
const playGame = (req, res) => { res.sendFile(process.cwd()+'/server/vr/index.html') }
TheplayGame
controller methodwill send theindex.html
placed in the /server...