Configuration backend service for mobile applications

To provide your mobile applications with centrally controlled configuration you need a backend service that can provide the applications with this. I developed and open sourced a backend service that provide this functionality, and this code is now made available as a service in Open Source Cloud.

This means that you don’t have to have your own cloud infrastructure to get started but you always have the option to do so as it is open source. In this blog post I will walk you through how you setup this service in Open Source Cloud.

Step 1: Create an account

If you already have an account at Open Source Cloud you can skip this step.

Head over to www.osaas.io and create a free account. Follow the procedure and create a new tenant.

Step 2: Create a Key / Value Store

To store the configuration variables we will use a Redis compatible key/value store called Valkey. This is also open source and has been made available as a service in Open Source Cloud.

There is of course nothing preventing you from using a Redis cloud service for this instead but in this post we will use services available in Open Source Cloud.

When you have logged on to the platform and created your tenant, go to browse and search for “valkey” and click on the card in the search result.

Click on the button “Create valkey” and give this instance a name. What name you choose is not important now.

Write down the IP and port found on the instance card for the Valkey instance that you just created.

Step 3: Create a configuration backend

Now it is time to create the configuration service backend. Navigate back to browse and search for “application config” and click on the card named “Application Config Service”.

Now press button “Create config-service” and enter a name of the config backend service and the Redis URL to the Valkey instance you created. Construct the Redis URL using the prefix redis:// and the IP and port you noted down earlier.

Wait until the service is ready and status “running” and then you can click on the instance card.

Insert a new configuration value by clicking on the Add new button in the top right corner. As an example we create a configuration variable called “hello” and with the value “world”.

Press create button and you will find the variable in the list.

Step 4: Use the configuration in your application

To get the address to the configuration value click on the “Copy to clipboard” icon and you can use this address in your application to fetch the variable.

As an example we can write this simple web application (entered in codepen.io):

Conclusion

You no longer need to build and host your own backend to provide the applications with configuration variables with this open source project available as a service in Open Source Cloud.

Live Transcoding with Open Source Cloud

As live streaming continues to grow in popularity across various platforms, building a scalable, resilient, and cost-effective architecture is essential for broadcasters and content providers. Whether you’re streaming live sports, news, or entertainment, ensuring that your content reaches audiences globally with minimal latency and interruptions is critical.

With Open Source Cloud, you can build a live streaming architecture that leverages open-source components to offer scalability, resilience, and customization — all at a lower cost.

Live Transcoding and CDN pull stream

In this scenario the CDN pulls the stream from the encoder instance in Open Source Cloud. We strongly recommend to place a CDN origin shield between the CDN distribution nodes and the encoder instance acting as origin.

This tutorial walks you through how to setup live transcoding using Open Source Cloud.

Prerequisites

  • If you have not already done so, sign up for an OSC account.
  • Be on a paid subscription plan.

For best guaranteed performance we recommend purchasing a reservation for at least 1 single premium node (200 EUR per month) but not required to getting started.

Step 1: Setup secrets

Go to the web user interface and navigate to the service called Eyevinn Live Encoding. Click on the tab Service Secrets and the button New Secret.

Create a secret called streamkeya containing mysecretkey. This will be the stream key the live production software will need to be able to push the stream to the encoder.

Step 2: Create encoder instance

In the web user interface click on the button “Create encoder +” and enter the following in the instance creation dialog.

  • Name: guide
  • HlsOnly: true
  • StreamKey: {{secrets.streamkeya}}

You will create one encoder instance for each live stream you want to distribute.

Step 3: Start encoder

Once the instance is up and running you can use the provided web user interface to start and stop the encoder.

Click on the instance card to open the web user interface and for automation and integration with API you find the live API documentation by clicking on the menu item Open API Docs.There you are presented with a web based REST API client ready to use.

To start the encoder click on the button START ENCODER. When the encoder is in status “starting” it is ready to receive the stream.

On the service card you find an IP and port in the format IP:PORT and these values are used when configuring your live production software (for example OBS). For example you enter rtmp://IP:PORT/live/mysecretkey as the stream destination in OBS.

As soon as the stream is being received by the encoder you will find a video playing the encoded stream.

Step 4: Watch the stream

You can play the HLS stream directly from the origin by opening an HLS capable video player to the address returned by the OSC tool. In this example it was https://demo-guide.eyevinn-live-encoding.auto.prod.osaas.io/origin/hls/index.m3u8.

Step 5: Stop the stream

When the live event has been completed you stop the stream in the live production software and when that is stopped you can stop the encoder by clicking on the button STOP ENCODER.

Step 6: Configure CDN

Configure your CDN and CDN origin shield to fetch the stream from the URL that you tested with your video player as a media origin.

Contact form and CAPTCHA backend in Open Source Cloud

With an open source backend service for form collection and CAPTCHA handling you can implement a contact form with spam protection without developing your own backend services for this. These backend services are also available in Open Source Cloud so you don’t have to host these backend services yourself either.

In this blog I will describe how you can quickly get a contact form where the message is sent to a Slack channel.

Create a Slack Bot

The Slack Bot will be the one posting the message to the channel in Slack. Visit https://api.slack.com/apps/ and create a new app with the permissions to post to the desired Slack channel.

Save the Slack Bot token as this will be used later in this tutorial.

Create form backend service in Open Source Cloud

Login to or signup for an account at Open Source Cloud.

Navigate to the Contact Form Service and click on the tab Service Secrets. Click on New Secret and add a secret that contains the Slack Bot token obtained earlier.

Image description

Create a contact form service by pressing the Create service button.

Image description

Give the service a name and select slack in the transport dropdown. Provide the service secret holding the token and enter the ID of the channel where the message should be posted.

Image description

When the service is up and running you can copy and save the URL to the contact form service.

Contact form example in React

Develop your contact form in your frontend application which in React could look something like this. Replace BACKEND-SERVICE-URL with the URL acquired above.



'use client';
import { Input, Textarea } from '@nextui-org/react';

export default function Page() {
  const handleSubmit = (formData: any) => {
    fetch(new URL('BACKEND-SERVICE-URL/contact'), {
      method: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      body: new URLSearchParams(formData).toString()
    });
  };

  return (
    <form action={handleSubmit}>
      <Input name="firstname" placeholder="First name" />
      <Input name="lastname" placeholder="Last name" />
      <Input name="email" placeholder="Your email" />
      <Textarea
        name="message"
        minRows={8}
        placeholder="Tell us a bit about what you want our help with"
      />
      <Input type="submit" value="Send" />
    </form>
  )
}
When the form is submitted you should now get a message in your Slack channel. To prevent spam-bots to misuse this form we need to add a CAPTCHA. CAPTCHA is an acronym that stands for "Completely Automated Public Turing test to tell Computers and Humans Apart."

To provide this functionality we will use an open source CAPTCHA backend service to generate and verify CAPTCHA. How it works is that you generate a CAPTCHA image that displays a text. Then you ask the user (human) to provide the text that he or she sees and the backend will verify that this was the text shown in the image.

Create CAPTCHA backend service in Open Source Cloud

Navigate to the CAPTCHA Service and click on the button Create service.

Image description

Give the service a name and once the service has started copy the URL to the service. Replace CAPTCHA-SVC-URL below with this URL.

Add CAPTCHA verification to your form

Extend the form we created above with the following code.



'use client';
import { Input, Textarea } from '@nextui-org/react'; 

export default function Page() {
  const [captchaSvg, setCaptchaSvg] = useState<string | null>(null);
  const [captchaId, setCaptchaId] = useState('');
  const [captcha, setCaptcha] = useState('');
  const [invalidCaptcha, setInvalidCaptcha] = useState(true);

  useEffect(() => {
    fetch(new URL('/captcha', 'CAPTCHA-SVC-URL'))
      .then((response) => response.json())
      .then((data) => {
        setCaptchaSvg(data.svg);
        setCaptchaId(data.id);
      });
  }, []);

  const onCaptchaChange = (value: string) => {
    setCaptcha(value);
    fetch(new URL('CAPTCHA-SVC-URL/verify/' + captchaId + '/' + value))
      .then((response) => {
        setInvalidCaptcha(!response.ok);
      })
      .catch(() => {
        setInvalidCaptcha(true);
      });
  };

  const handleSubmit = (formData: any) => {
    fetch(new URL('BACKEND-SERVICE-URL/contact'), {
      method: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      body: new URLSearchParams(formData).toString()
    });
  };

  return (
    <form action={handleSubmit}>
      <Input name="firstname" placeholder="First name" />
      <Input name="lastname" placeholder="Last name" />
      <Input name="email" placeholder="Your email" />
      <Textarea
        name="message"
        minRows={8}
        placeholder="Tell us a bit about what you want our help with"
      />

      {captchaSvg && (
        <Image src={captchaSvg} className="bg-white" alt="Captcha" />
      )}

      <Input
        name="captcha"
        placeholder="Enter the text from the image"
        description="This is used to prevent automated submissions."
        required
        maxLength={4}
        value={captcha}
        onValueChange={onCaptchaChange}
      />
      <Input type="submit" value="Send" isDisabled={invalidCaptcha} />
    </form>
  )
}


Conclusion

This was an example on how you can add to your web application a contact form with CAPTCHA verification that posts to a Slack channel without having to build or host your own backend services for it.

What is Open Source Cloud?

Open Source Cloud reduces the barrier to get started using open source and reduces the barrier for creators to make their software available as a service. Read more about why we developed it in this post.