You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 24, 2025. It is now read-only.
The new functions.post method assumes a JSON body and sets Content-Type and Accept headers to application/json. Review if this behavior is consistent with other SDK modules and whether it could cause issues for endpoints expecting different content types or header values.
constpost=async<T=any>(path: string,body?: unknown,options: RequestInit={},): Promise<FetchResponse<T|string|Blob>>=>{// Ensure the method is POST and set the bodyconstrequestOptions: RequestInit={
...options,method: "POST",headers: {Accept: "application/json","Content-Type": "application/json",
...options.headers,},body: body ? JSON.stringify(body) : undefined,};returnfetch<T>(path,requestOptions);};
The function checks for accept header values but does not handle cases where the header contains multiple values (e.g., "application/json, text/plain"). This could lead to unexpected 400 errors. Consider reviewing header parsing logic for robustness.
if(!req.headers.accept||req.headers.accept==="text/plain"){res.setHeader("Content-Type","text/plain");returnres.status(200).send("Hello, World!");}// if accept is set to application/json, return JSONif(req.headers.accept==="application/json"){res.setHeader("Content-Type","application/json");returnres.status(200).json({message: "Hello, World!"});}// fail with 400res.setHeader("Content-Type","text/plain");res.status(400).send("Unsupported Accept Header");
Make Accept header handling robust and case-insensitive
The check for req.headers.accept is case-sensitive and does not account for Accept headers with multiple values (e.g., "application/json, text/plain"). This can cause the function to not respond with the expected content type. Consider parsing the Accept header and performing a case-insensitive match for more robust content negotiation.
Why: The suggestion correctly identifies a real-world bug: the Accept header is case-sensitive and may contain multiple comma-separated values, which the original code does not handle. The improved code makes the check case-insensitive and robust to multiple values, improving API correctness and client compatibility. This is a significant improvement for HTTP content negotiation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Enhancement, Documentation, Tests
Description
Add
functions.postmethod for serverless POST requestsImprove and expand SDK documentation and usage examples
Enhance error handling and test coverage for all modules
Add movies table, migration, and seed data for GraphQL demos
Changes diagram
Changes walkthrough 📝
6 files
Add example serverless function for testing POST/GETAdd movies table metadata and public select permissionsRegister movies table in tables metadataMigration to drop movies tableMigration to create movies table and seed demo dataAdd post() method to Functions client for JSON POST requests4 files
Update auth version in Nhost configAdd moduleNameMapper for package path aliasesAdd path aliases for package submodulesUpdate nixops and add nix2container to flake inputs11 files
Update module descriptions for accuracyRewrite and expand Auth module documentationRewrite and expand Functions module documentation, add post() docsRewrite and expand GraphQL module documentation with examplesUpdate main usage example and documentationRewrite and expand Storage module documentation with examplesRewrite and expand Auth module JSDoc, update error handling docsRewrite and expand Functions module JSDoc, add post() docsRewrite and expand GraphQL module JSDoc with examplesRewrite main SDK JSDoc, update usage exampleRewrite and expand Storage module JSDoc with examples10 files
Use package path aliases in auth testsExpand main usage test, add function call, update importsAdd tests for functions.post and improve coverageUse package path aliases in GraphQL testsUse package path aliases in Nhost client testsUse package path aliases in storage testsExpand auth error handling tests and usage examplesAdd and expand functions usage and error handling testsExpand GraphQL usage and error handling tests, add movies demoExpand storage usage and error handling tests2 files
Update Next.js and related dependencies, lockfile changesAdd Next.js version override to workspace config