{"id":18569071,"url":"https://github.com/dainfloop/replace-replit","last_synced_at":"2025-04-10T06:31:59.185Z","repository":{"id":198975078,"uuid":"701921822","full_name":"DaInfLoop/replace-replit","owner":"DaInfLoop","description":null,"archived":false,"fork":false,"pushed_at":"2023-10-16T22:41:01.000Z","size":126,"stargazers_count":4,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-10-17T10:08:10.347Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://npm.im/repl-auth","language":"TypeScript","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/DaInfLoop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-08T01:01:35.000Z","updated_at":"2023-10-16T22:52:29.000Z","dependencies_parsed_at":"2023-10-17T04:47:42.814Z","dependency_job_id":"556042ca-e433-456e-900d-f955ec7661b6","html_url":"https://github.com/DaInfLoop/replace-replit","commit_stats":null,"previous_names":["dainfloop/replauth"],"tags_count":5,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaInfLoop%2Freplace-replit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaInfLoop%2Freplace-replit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaInfLoop%2Freplace-replit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaInfLoop%2Freplace-replit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DaInfLoop","download_url":"https://codeload.github.com/DaInfLoop/replace-replit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223427671,"owners_count":17143329,"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":[],"created_at":"2024-11-06T22:32:02.005Z","updated_at":"2024-11-06T22:33:02.943Z","avatar_url":"https://github.com/DaInfLoop.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# replace-replit\n\nUse some of Replit's features in your project without hosting on Replit.\n\n## Usage\n\n### ReplAuth\n\nThe ReplAuth module only supports express and socket.io currently.\n\n```js\nimport { auth } from \"replace-replit\";\nimport express from \"express\";\nimport { createServer } from 'node:http';\nimport { Server } from 'socket.io';\n\nconst app = express();\nconst server = createServer(app);\nconst io = new Server(server);\napp.use(auth.express());\n\napp.get('/', (req, res) =\u003e {\n  const username = req.get(\"X-Replit-User-Name\");\n\n  if (username)\n    res.send(`Hello, ${username}!`);\n  else\n    res.send(`Hello, World!`);\n});\n\nio.use(auth.socketIo({ exposeAs: \"user\" }))\n\nio.on('connection', (socket) =\u003e {\n  console.log('connection from', socket.user.name)\n})\n\nserver.listen(8000, () =\u003e {\n  console.log(\"App is running on port 8000\");\n});\n```\n\n### ReplDB\n\nThe ReplDB module only supports express and socket.io currently.\n\n```js\n// server.js\nimport { db } from \"replace-replit\";\nimport express from \"express\";\n\nconst app = express();\napp.use(db.express({\n  file: \"database.json\",\n  fileType: \"json\"\n}));\n\napp.listen(8000, () =\u003e {\n  console.log(\"App is running on port 8000\");\n});\n\n// test.js\nimport Database from \"@replit/database\";\n\nconst db = new Database(\"http://localhost:8000\");\n\nawait db.set(\"hello\", \"world\")\n\nawait db.get(\"hello\") // world\n```\n\n## Options\n\n### ReplAuth\nCurrently there is only one option passable to the `auth` middleware:\n\n`exposeAs` will allow you to control what an object containing the user data will be set to:\n\n```js\napp.use(auth.express({ exposeAs: \"user\" }))\n\n// In a route handler...\nreq.user.name // contains the user's username\n```\n\n### ReplDB\nThere are 4 options passable to the `db` middleware:\n\n`file`: Controls what file your database will be saved to.\n`fileType`: Controls what type your file will use. Values can either be `json`, `toml`, `ini`, or `custom` (see below):\n\n`parse`: Function that takes two arguments, data (the file contents) and fileType (the fileType passed to the middleware).\n\n```js\ndb.express({\n  // ...\n  parse(data, fileType) {\n    if (fileType == \"...\") {\n      // do stuff\n      return TheResultingDataInAnObject\n    } else {\n      throw new Error('i dunno what this file type is')\n    }\n  }\n})\n```\n\n`stringify`: Function that takes two arguments, data (the current db object) and fileType (the fileType passed to the middleware).\n\n```js\ndb.express({\n  // ...\n  stringify(data, fileType) {\n    if (fileType == \"...\") {\n      // do stuff\n      return TheResultingDataInAString\n    } else {\n      throw new Error('i dunno what this file type is')\n    }\n  }\n})\n```\n\n# Acknowledgements\n\n[PotentialStyx](https://replit.com/@PotentialStyx) - Helped me with verifying the JWT  \n[PikachuB2005](https://replit.com/@PikachuB2005) - Donated the package name to me  \n[coding398](https://replit.com/@codingMASTER398) - Cool tester + has great ideas + bug fixer\n[DillonB07](https://replit.com/@DillonB07) - Helped on the README\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdainfloop%2Freplace-replit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdainfloop%2Freplace-replit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdainfloop%2Freplace-replit/lists"}