What is the best way to access the express app within Keystone 6?

I'm currently working with Keystone 6 as my backend system and I'm facing the challenge of integrating Stripe. Stripe requires access to the underlying express app in order to pass a client secret from the server to the client, as explained in their documentation here: https://stripe.com/docs/payments/payment-intents#passing-to-client

Despite referring to the documentation, I am struggling to find a way to access the express app within Keystone 6. The documentation does not provide any guidance on this matter. Any assistance on this issue would be greatly appreciated.

Answer №1

In the current version of Keystone 6, the feature you're looking for is not supported yet.

However, there are indications that this functionality will be added soon:

Development of this feature is in progress

The team at Keystone has acknowledged the need for this feature and it has been given a higher priority. An update to the public roadmap reflecting this change is expected next week. The actual implementation should follow shortly thereafter, although an exact release date cannot be provided at this time.

Potential workaround for accessing the Express app

While it may be challenging at present, it is technically possible to access the Express app within Keystone. By examining Keystone's 'start' command, which includes the function call to createExpressServer(), you can gain insight into how to leverage this functionality. It is even feasible to customize and run the code directly without relying on the built-in 'keystone start' command.

For instance, you could substitute the existing code with your custom endpoint like so:

const server = express();
server.get('/hello-world', (req, res) => {
  res.send('Hello');
});

const keystoneServer = await createExpressServer(
  config,
  graphQLSchema,
  keystone.createContext,
  false,
  getAdminPath(cwd)
);
server.use(keystoneServer);

This setup allows your '/hello-world' endpoint to take precedence over Keystone's default configuration. Keep in mind that this approach may not work seamlessly with the 'dev' command in the local environment and alternative strategies might be necessary.

One potential solution is to run a separate express server on a different port to accommodate your custom routes. While incorporating distinct URLs for various environments can be cumbersome, it is still a viable workaround within the Keystone application codebase. Utilizing environment variables for defining custom endpoints in production and development settings can help manage this complexity.

# Production
GRAPHQL_ENDPOINT="https://api.example.com/api/graphql"
CUSTOM_ENDPOINT="https://api.example.com/hello-world"
# Dev
GRAPHQL_ENDPOINT="http://localhost:3000/api/graphql"
CUSTOM_ENDPOINT="http://localhost:3100/hello-world"

Although this method may seem inelegant, it offers a functional solution until official support for the desired functionality is integrated into Keystone 6. Rest assured, I will provide further updates once this feature is officially available.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using a .NET Web-API controller variable as a parameter in a JavaScript function

I am looking to send a "variable" from the controller to a JavaScript function. The code I have implemented is as below: <div ng-controller="faqController"> <div ng-repeat="c in categories"> <h2 onclick="toggle_visibility(&apos ...

Having trouble with the babel-loader and its version compatibility, as well as not finding the babel-loader folder in the node_modules directory when

Here are the steps I've taken: I cloned the project from Github. Ran the command 'yarn' to start the project. Encountered an error after running the command 'yarn start'. Even after following the steps provided in the e ...

Issue with Material-UI tab when using a datatable within it's content

I implemented the Simple Tabs feature from Material-UI with a Tab containing a Datatable using React-Data_Table. However, I noticed that this particular tab is not responsive like the others when the table is full. Empty Full Here's a snippet of th ...

Timeout error encountered in communication between SenecaJS service and Express API due to client request exceeding

I am in the process of using SenecaJS to create a microservices-oriented application. Initially, I have outlined a single microservice that contains only one action at this point. This specific action is designed to run a time-intensive shell command (appr ...

The default value is not displayed in the Angular dropdown menu

When using regular html select menus, if you create an option element with selected and disabled attributes and provide text for that option, the text will be displayed by default in the select menu. Below is a basic example of HTML code: <select name= ...

Tips for running multiple .js test files simultaneously with npm (pact files)

My background is in Java and Maven, where I am accustomed to running multiple test files together and sequentially using a command like: mvn '-Dtest=com.my.directory.tests.*Test' test In this setup, all my test files are named to end with the w ...

Waiting for state changes in React by using the UseState Hook

I am currently working on a function that manages video playback when clicked, and I need to set consecutive states using the useState hook. However, I want to ensure that the first state is completed before moving on to the next setState without relying ...

Currently, the nodemailer isn't working properly for express post requests

I have recently developed an express app with a functional contact form that successfully sends test emails in a local environment. I have configured nodemailer to work with different environments, all currently using temporary test email addresses. Howe ...

What is the best way to prematurely exit an outer function when there are multiple inner non-blocking function calls?

For the purpose of learning, I am working on creating a basic version of async.parallel. The description from the documentation is as follows: parallel(tasks, [callback]) Run the tasks array of functions in parallel, without waiting until the previou ...

Exploring the power of promises in the JavaScript event loop

Just when I thought I had a solid understanding of how the event loop operates in JavaScript, I encountered a perplexing issue. If this is not new to you, I would greatly appreciate an explanation. Here's an example of the code that has left me scratc ...

Step-by-step guide on transforming jQuery code into Vue JS:

Recently delving into Vue, attempting to translate previous JS + JQuery code into Vue Here is the list I'm working with: <ul id="progressbar"> <li class="active">integration Ip's</li> <li>T ...

ES6 arrow function fails to recognize the 'this' operator after being transpiled into JavaScript

Currently, I am developing a node application that undergoes transpilation from TypeScript ES6 to JavaScript ES6. To manage class dependencies, I am employing inversify for dependency injection. However, I encountered an error while trying to access member ...

The jQuery ajax request was unsuccessful in connecting to the remote server

I've tried researching and troubleshooting, but I still can't figure out why the Ajax code is not functioning correctly. Here is my JavaScript code: $(document).ready(function(){ $("#tform").submit(function() { var varUserName ...

Error 8007 encountered when attempting to scale at 100% proficiency. Transformation unsuccessful

Wondering if this could be a bug in Photoshop. When scaling a layer and entering values of 100%, an error message pops up: var srcDoc = app.activeDocument; var numOfLayers = srcDoc.layers.length; // main loop for (var i = numOfLayers -1; i >= 0 ; i-- ...

Is it possible to modify a particular entry in Ember Data without initiating any HTTP requests?

Within my Ember.js application, I have a model named emails structured as follows: import DS from 'ember-data'; export default DS.Model.extend({ label : DS.attr('string'), primary : DS.attr('string'), email : ...

Adding a solo value to an array after submitting a form

I am currently working on a registration form that allows users to select multiple dates for an event using checkboxes. These selected dates are then added to an array within the formObject. In order to transfer this data to a Google sheet, I check the len ...

Text field value dynamically changes on key press update

I am currently working on the following code snippet: {% for item in app.session.get('aBasket') %} <input id="product_quantity_{{ item['product_id'] }}" class="form-control quantity" type="text" value="{{ item['product_quan ...

Is there a way to incorporate the MUI theme color into inline styles?

Imagine I have the following tabs displayed below. Is there a way to implement MUI's primary and secondary colors for inline CSS? My goal is to personalize the colors using my own palette. <Tabs value={value} ...

Embedding links in v-bind:href

I inserted a dynamic link inside the <header></header> section using the method mentioned here: Vue JS and appending a variable to end of a URL Below are the relevant codes: <tr class="notice-row" v-for="(myCase, id) in case ...

Is JavaScript the go-to solution for rearranging a list of objects?

I have come across a data structure related question that I believe would be best addressed in this forum. Recently, I have been encountering the following issue frequently. I receive data from a service in the following format. It consists of an array of ...