Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial nextjs api endpoint commit #46

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dgading
Copy link
Contributor

@dgading dgading commented Dec 19, 2024

This PR aims to create a NextJS api endpoint that can update the homepage goals search. With NextJS Drupal, each request for information needs authorization credentials passed with it. NextJS uses environmental variables to do this when building the site with functions like getStaticProps. These credentials are never passed to the browser, so updating the site with new data from the view can't be done like a normal React application where you just fetch some new data.

In NextJS, using the api subfolder in the pages folder, you can create API end points that live on the server part of the NextJS application. These pages are never sent to the browser, but can be used be the browser part of the site to access the Drupal site. In this PR I've added the endpoint /api/goal-search which can take a query of fulltext. This endpoint then works similar to the getStaticProps on page load, when a request hits the endpoint, it sends a graphql query to the Drupal site with the auth information and returns the information through my new endpoint to the browser application. When using the application, if you use the goals search, you will never see the Drupal endpoint, only the NextJS api endpoint I created.

@dgading
Copy link
Contributor Author

dgading commented Jan 15, 2025

Linking the NextJS tutorial page which probably explains it better than I did https://nextjs.org/learn-pages-router/basics/api-routes

@openprivacy
Copy link
Member

@dgading thanks for the link - quite a rabbit hole that I never got to the bottom of. It seems NextJS is being secure here, but as with writing any APIs, whoever reviews your code should keep the OWASP API Top 10 in mind.
https://owasp.org/API-Security/editions/2023/en/0x11-t10/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants