Merge pull request #226 from cashpipeplusplus/master

docs: Add instructions for Google App Engine deployment
This commit is contained in:
Alex Sosnovskiy 2020-11-24 10:28:49 +03:00 committed by GitHub
commit cbc7cbf526
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -251,6 +251,67 @@ This will start a peerjs server on port 9000 exposed on port 9000 with key `peer
Open your browser with http://localhost:9000/myapp It should returns JSON with name, description and website fields. http://localhost:9000/myapp/peerjs/id - should returns a random string (random client id) Open your browser with http://localhost:9000/myapp It should returns JSON with name, description and website fields. http://localhost:9000/myapp/peerjs/id - should returns a random string (random client id)
## Running in Google App Engine
Google App Engine will create an HTTPS certificate for you automatically,
making this by far the easiest way to deploy PeerJS in the Google Cloud
Platform.
1. Create a `package.json` file for GAE to read:
```sh
echo "{}" > package.json
npm install express@latest peer@latest
```
2. Create an `app.yaml` file to configure the GAE application.
```yaml
runtime: nodejs
# Flex environment required for WebSocket support, which is required for PeerJS.
env: flex
# Limit resources to one instance, one CPU, very little memory or disk.
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 0.5
```
3. Create `server.js` (which node will run by default for the `start` script):
```js
const express = require('express');
const { ExpressPeerServer } = require('peer');
const app = express();
app.enable('trust proxy');
const PORT = process.env.PORT || 9000;
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('/', peerServer);
module.exports = app;
```
4. Deploy to an existing GAE project (assuming you are already logged in via
`gcloud`), replacing `YOUR-PROJECT-ID-HERE` with your particular project ID:
```sh
gcloud app deploy --project=YOUR-PROJECT-ID-HERE --promote --quiet app.yaml
```
## Privacy ## Privacy
See [PRIVACY.md](https://github.com/peers/peerjs-server/blob/master/PRIVACY.md) See [PRIVACY.md](https://github.com/peers/peerjs-server/blob/master/PRIVACY.md)