Skip to content

Server side SDK

This SDK can be used on frameworks leveraging Server Side Rendering but also on raw Node.js applications.

Installation

Terminal window
$ npm install --save @progressively/server-side

Usage

Initial setup

Let’s imagine that we work on a Nextjs. In this application, we have the following page:

import { ProgressivelyProvider, useFlags } from "@progressively/react";
const FlaggedComponent = () => {
const { flags } = useFlags();
/* ... */
};
// The progressivelyProps will be passed from the server
const YourPage = ({ progressivelyProps }) => {
return (
<ProgressivelyProvider {...progressivelyProps}>
<FlaggedComponent />
</ProgressivelyProvider>
);
};

Server usage without stickiness

You may see different variants of the feature flag when not using stickiness.

import { Progressively } from "@progressively/server-side";
export async function getServerSideProps({ req }) {
// Agnostic cross-framework SSR call
const sdk = Progressively.init({
secretKey: "secret-key", // necessary AND: SECRET DO NOT SHARE
clientKey: "valid-sdk-key", // useful for passing it down to the client
websocketUrl: "ws://localhost:4000", // only necessary when self hosting
apiUrl: "http://localhost:4000", // only necessary when self hosting
});
const { data, response } = await sdk.loadFlags();
return {
props: {
progressivelyProps: data,
},
};
}

Server usage with stickiness

You are reponsible for setting the ID field if you want to have stickiness between the server rendering and the client rendering. This ID can be stored in database, in a cookie or wherever makes sense to you

import { Progressively } from "@progressively/server-side";
export async function getServerSideProps({ req }) {
const sdk = Progressively.init({
secretKey: "secret-key",
clientKey: "valid-sdk-key",
websocketUrl: "ws://localhost:4000",
apiUrl: "http://localhost:4000",
fields: {
id, // You know this ID, it's yours, get it from your place
},
});
const { data } = await sdk.loadFlags();
return {
props: {
progressivelyProps: data,
},
};
}