The Node express API for CodeVideo video creation. Uses codevideo-backend-engine behind the scenes.
Install dependencies:
npm installStart the server:
npm startThis will start the server on http://localhost:7000.
Simply call https://api.codevideo.io/create-video-v3 with a JSON body corresponding to an array of actions (IAction from `@fullstackcraftllc/codevide-types), and we handle the rest. You must be signed in to use this endpoint.
The V3 endpoint has 3 parts:
- the main express entry point, which first builds all the needed audio for the video
go-video-dispatcher, which calls therecordVideoV3.jsnode script to record the- the
recordVideoV3.jsscript, which uses puppeteer to record the actual video
V2 was what I called the desktop driver for visual studio code and never build an API for that... maybe someday.
Simply call https://api.codevideo.io/generate-video-immediately with a JSON body corresponding to the interface defined in IGenerateVideoFromActionsOptions in codevideo-backend-engine
This is a first-in-first-out endpoint, so expect this URL to get gunked up as CodeVideo gains traction (if ever, lol). Here is an example calling the API using bash:
curl -s -X POST \
-H "Content-Type: application/json" \
-d '{
"actions": [
{
"name": "author-speak-before",
"value": "Welcome to the amazing world of CodeVideo. Here'\''s some code!"
},
{
"name": "editor-type",
"value": "console.log('\''hello world!'\'');"
}
],
"language": "javascript",
"textToSpeechOption": "elevenlabs",
"ttsApiKey": "YOUR_ELEVENLABS_API_KEY",
"ttsVoiceId": "YOUR_VOICE_ID"
}' \
https://api.codevideo.io/create-video-immediatelyAnd using TypeScript:
const response = await fetch("https://api.codevideo.io/generate-video-immediately", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
actions,
language,
textToSpeechOption,
}),
});
const data = await response.json()
// bucket url to mp4 file
console.log(data.url)First, make sure you have a .env file wherever you are going to run this API. (See .env.example in the root of the project and .env.example in the go-video-dispatcher folder).
*Note: we know Docker stuff is a pain in the ass, so note here we are using the newer docker compose and docker-compose syntax.
Build the Docker services:
docker compose buildThen start up the various containers (which includes the Express server, go microservice, puppeteer runner, and static Gatsby site for recording) and NGINX container:
docker compose up -dFull restart:
docker compose build && docker compose up -dDue to issues with headless chromium playing audio, we run the go dispatcher locally (which also calls the puppeteer script). To run that:
First install dependencies for the puppeteer part:
cd go-video-dispatcher/puppeteer-runner
npm install
cd ..
go build
nohup ./go-video-dispatcher &You'll need a S3 bucket or similar to store the videos.
Rename nginx/conf/api.codevideo.io.conf to nginx/conf/yoursitename.com.conf
Rename all instances of api.codevideo.io in that .conf file to your site name, and ensure the 443 block is commented out.
To dry run (this example for api.codevideo.io)
docker compose run --rm certbot certonly --webroot --webroot-path /var/www/certbot/ -d api.codevideo.io --dry-runor for staging.api.codevideo.io
docker compose run --rm certbot certonly --webroot --webroot-path /var/www/certbot/ -d staging.api.codevideo.io --dry-runIf the dry run works, issue the certbot command without --dry-run:
docker compose run --rm certbot certonly --webroot --webroot-path /var/www/certbot/ -d api.codevideo.ioor for staging.api.codevideo.io
docker compose run --rm certbot certonly --webroot --webroot-path /var/www/certbot/ -d staging.api.codevideo.ioNote that after renewing a cert you will need to restart the NGINX container:
docker restart <container-name-or-id-here>Because the certbot image is mapped to folders in this repository, your certs will be in certbot/conf/live/ folder.
You can now uncomment the 443 block in your .conf file and restart the NGINX container:
docker compose down && docker compose up -dEnsure you are in the root of this project (we need to be able to read docker-compose.yml) then run:
docker compose run --rm certbot renewnpm test