1. create app folder:
mkdir myapp
2. cd to folder myapp and run below below command to install PeerJS:
npm install express@latest peer@latest
3. upload the folder "myapp" to your site root
4. create server.js file with below content and save it to myapp:
const express = require('express');
const { ExpressPeerServer } = require('peer');
const app = express();
app.enable('trust proxy');
const PORT = process.env.PORT;
const server = app.listen(PORT, () => {
console.log(`App listening on port ${PORT}`);
console.log('Press Ctrl+C to quit.');
});
const peerServer = ExpressPeerServer(server, {
path: '/'
});
app.use('/myapp', peerServer);
module.exports = app;
5. go to hosting control panel to enable NodeJS for this sub folder "myapp"
6. update web.config in myapp with below content:
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="mysite">
<match url="/*" />
<action type="Rewrite" url="server.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Open your browser with http://xxxx/myapp It should returns JSON with name, description and website fields.
Article ID: 2193, Created: August 27, 2021 at 2:30 AM, Modified: August 27, 2021 at 2:30 AM