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.