{"id":22466445,"url":"https://github.com/coreh/next-http","last_synced_at":"2025-03-27T15:18:47.586Z","repository":{"id":66096198,"uuid":"124591461","full_name":"coreh/next-http","owner":"coreh","description":"Mount arbitrary HTTP request handlers (including Connect, Express \u0026 Koa apps / middleware) as Next.js pages","archived":false,"fork":false,"pushed_at":"2018-03-09T21:20:46.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-01T19:12:49.275Z","etag":null,"topics":["connect","express","expressjs","http","middleware","next","nextjs","react","request"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coreh.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"License.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-09T20:46:38.000Z","updated_at":"2018-03-09T21:16:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"604d3eb8-1af6-4696-8178-5f19eef7faa9","html_url":"https://github.com/coreh/next-http","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coreh%2Fnext-http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coreh%2Fnext-http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coreh%2Fnext-http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coreh%2Fnext-http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coreh","download_url":"https://codeload.github.com/coreh/next-http/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245868328,"owners_count":20685609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["connect","express","expressjs","http","middleware","next","nextjs","react","request"],"created_at":"2024-12-06T10:12:17.674Z","updated_at":"2025-03-27T15:18:47.559Z","avatar_url":"https://github.com/coreh.png","language":"JavaScript","readme":"# next-http\n\n![npm](https://img.shields.io/npm/v/npm.svg)\n![license](https://img.shields.io/github/license/coreh/next-http.svg)\n\nHigher Order Component to mount arbitrary HTTP request handlers as [Next.js](https://github.com/zeit/next.js) pages. (When rendering on the server side.)\n\nAllows to more easily expose custom handlers (e.g. for simple API endpoints) while still leveraging Next.js's bundling, transpilation, routing and hot code reloading functionality.\n\nCompatible with [Connect](https://github.com/senchalabs/connect), [Express](http://expressjs.com) and [Koa](https://github.com/koajs/koa) apps / middleware.\n\n**Important:** Rendering this component on the client side will result in an error. To prevent shipping your back end code to the client side, you should instruct webpack to ignore the server-only files via `webpack.IgnorePlugin`. [See the example below](#nextconfigjs).\n\n## Example\n\n### pages/api/my-endpoint.js\n\n```js\nimport http from 'next-http';\nimport connect from 'connect';\n\nconst app = connect();\n\napp.use((req, res) =\u003e {\n    res.setHeader('Content-Type', 'text/plain');\n    res.end('Hello, world');\n});\n\nexport default http(app);\n```\n\n**Note:** We'e using Connect here for for illustration purposes, you could also use Express, Koa or write your own handler function directly\n\n### next.config.js\n\n```js\nconst webpack = require('webpack');\n\nmodule.exports = {\n    webpack: (config, { buildId, dev, isServer, defaultLoaders }) =\u003e {\n        if (!isServer) {\n            // Exclude all paths starting with ./pages/api/ from webpack builds\n            config.plugins.push(new webpack.IgnorePlugin(/^\\.\\/pages\\/api\\/.*$/))\n        }\n        return config\n    },\n}\n```\n\n## FAQ\n\n### Q. What's the point of using this instead of just responding to HTTP requests directly on `getInitialProps()`?\n\nMostly to reduce boilerplate. This module will gracefully wait until the HTTP request handler is done serving the request. It also looks cleaner IMO.\n\n### Q. How can I handle POST / DELETE / PUT requests? I get a `501 Not Implemented` response from Next.js\n\nNext.js will by default refuse non GET / HEAD HTTP requests on its filesystem router. You'll need to use a [custom server with routing](https://github.com/zeit/next.js/#custom-server-and-routing).\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoreh%2Fnext-http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoreh%2Fnext-http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoreh%2Fnext-http/lists"}