Skip to content

Commit 1a8d880

Browse files
committed
Better VCR support
1 parent 3e3cd2d commit 1a8d880

File tree

10 files changed

+1151
-3107
lines changed

10 files changed

+1151
-3107
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,7 @@ jspm_packages
4242
/.idea/
4343
.DS_Store
4444

45-
neru.yml
45+
neru.yml
46+
vcr.yml
47+
vcr-build/
48+
release/

Procfile

Lines changed: 0 additions & 1 deletion
This file was deleted.

install.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npm install

package-lock.json

Lines changed: 1053 additions & 3088 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"version": "0.0.0",
44
"private": true,
55
"scripts": {
6-
"start": "node ./bin/www"
6+
"start": "node ./bin/www",
7+
"vcr-build": "node vcr-build.js"
78
},
89
"dependencies": {
910
"@vonage/server-sdk": "^3.0",
@@ -25,6 +26,8 @@
2526
"unique-names-generator": "^4.7.1"
2627
},
2728
"devDependencies": {
28-
"nodemon": "^2.0.22"
29+
"archiver": "^6.0.1",
30+
"nodemon": "^3.0.2",
31+
"simple-git": "^3.21.0"
2932
}
3033
}

routes/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ router.post("/sip/:room/dial", async function (req, res) {
331331
token,
332332
sip: {
333333
auth: {
334-
username: process.env.API_KEY,
335-
password: process.env.API_SECRET,
334+
username: process.env.VCR_API_ACCOUNT_ID,
335+
password: process.env.VCR_API_ACCOUNT_SECRET,
336336
},
337337
uri: `sip:${process.env.CONFERENCE_NUMBER}@sip.nexmo.com;transport=tls`,
338338
secure: false,

setup.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
{
22
"data": [
3-
{
4-
"type": "TEXT",
5-
"title": "Vonage API Key",
6-
"description": "Your Vonage API Key. This is needed to enable SIP Functionality",
7-
"name": "API_KEY"
8-
},
9-
{
10-
"type": "SECRET",
11-
"title": "Vonage API Secret",
12-
"description": "Your Vonage API Secret. This is needed to enable SIP Functionality",
13-
"name": "API_SECRET"
14-
},
153
{
164
"type": "PHONE_NUMBER",
175
"title": "SIP Conference Number",

vcr-build.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const simpleGit = require('simple-git');
4+
const archiver = require('archiver');
5+
6+
const vcrBuildDir = path.join(__dirname, 'vcr-build');
7+
const releaseDir = path.join(__dirname, 'release');
8+
const repoUrl = 'https://github.com/Vonage-Community/sample-video-node-learning_server.git';
9+
10+
// Check for version argument
11+
const version = process.argv[2];
12+
if (!version) {
13+
console.error('Error: Version argument is required. Usage: npm run vcrbuild <version>');
14+
process.exit(1);
15+
}
16+
17+
const zipFileName = `vcr-build-${version}.zip`;
18+
19+
async function runVcrBuild() {
20+
try {
21+
// Check if the release file already exists
22+
if (fs.existsSync(path.join(releaseDir, zipFileName))) {
23+
console.error(`Error: Release file for version ${version} already exists.`);
24+
process.exit(1);
25+
}
26+
27+
// Create release directory if it doesn't exist
28+
if (!fs.existsSync(releaseDir)) {
29+
fs.mkdirSync(releaseDir);
30+
}
31+
32+
// Step 1: Delete vcr-build directory if it exists
33+
if (fs.existsSync(vcrBuildDir)) {
34+
fs.rmSync(vcrBuildDir, { recursive: true });
35+
}
36+
37+
// Step 2: Perform a clean checkout of the repository
38+
await simpleGit().clone(repoUrl, vcrBuildDir);
39+
40+
// Step 3: Copy vcr.yml to vcr-build
41+
const neruFilePath = path.join(vcrBuildDir, 'vcr.yml.dist');
42+
fs.copyFileSync(neruFilePath, path.join(vcrBuildDir, 'vcr.yml'));
43+
fs.rmSync(vcrBuildDir + '/.git', { recursive: true })
44+
fs.rmSync(vcrBuildDir + '/.gitignore')
45+
fs.rmSync(neruFilePath)
46+
47+
// Step 4: Create a ZIP file from vcr-build with version name
48+
await createZipFile(vcrBuildDir, zipFileName);
49+
50+
console.log(`VCR build process completed successfully. File created: ${zipFileName}`);
51+
} catch (error) {
52+
console.error('Error during VCR build process:', error);
53+
}
54+
}
55+
56+
async function createZipFile(sourceDir, zipFileName) {
57+
return new Promise((resolve, reject) => {
58+
const output = fs.createWriteStream(path.join(releaseDir, zipFileName));
59+
const archive = archiver('zip', { zlib: { level: 9 } });
60+
61+
output.on('close', () => resolve());
62+
archive.on('error', (err) => reject(err));
63+
64+
archive.pipe(output);
65+
archive.directory(sourceDir, false);
66+
archive.finalize();
67+
});
68+
}
69+
70+
runVcrBuild();

vcr.yml.dist

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
project:
2+
name: vonage-video-backend-server
3+
instance:
4+
name: dev
5+
runtime: nodejs18
6+
region: aws.use1
7+
build-script: ./install.sh
8+
entrypoint:
9+
- npm
10+
- start
11+
12+
debug:
13+
entrypoint:
14+
- npm
15+
- start

views/index.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ html(lang='en')
1616
}
1717
body
1818
p
19-
| This is a sample web service for use with Vonage Video Node SDK. See the Vonage
19+
| This is a sample web service for use with Vonage Video Node SDK. See the Vonage
2020
a(href='https://github.com/opentok/learning-opentok-node')
2121
| learning-opentok-node
2222
| repo on GitHub.

0 commit comments

Comments
 (0)