prepare npm publish
This commit is contained in:
		
							parent
							
								
									9705b01fdc
								
							
						
					
					
						commit
						4528a96ded
					
				
							
								
								
									
										1
									
								
								.npmignore
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.npmignore
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | ||||
| !dist/ | ||||
							
								
								
									
										32
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								README.md
									
									
									
									
									
								
							| @ -1,39 +1,51 @@ | ||||
| # Fosscord API Server | ||||
| This repository contains the HTTP API Server | ||||
| 
 | ||||
| This repository contains the Fosscord HTTP API Server | ||||
| 
 | ||||
| ## Bug Tracker | ||||
| 
 | ||||
| [Project Board](https://github.com/fosscord/fosscord-api/projects/2) | ||||
| 
 | ||||
| ## API | ||||
| 
 | ||||
| We use [express](https://expressjs.com/) for the HTTP Server and  | ||||
| We use [express](https://expressjs.com/) for the HTTP Server and | ||||
| [lambert-server](https://www.npmjs.com/package/lambert-server) for route handling and body validation (customized). | ||||
| 
 | ||||
| ## Contribution | ||||
| You should be familiar with: | ||||
| - [Git](https://git-scm.com/) | ||||
| - [NodeJS](https://nodejs.org/) | ||||
| - [TypeScript](https://www.typescriptlang.org/) | ||||
| - [MongoDB/mongoose](http://mongoosejs.com/) | ||||
| 
 | ||||
| and the other technologies we use  | ||||
| You should be familiar with: | ||||
| 
 | ||||
| -   [Git](https://git-scm.com/) | ||||
| -   [NodeJS](https://nodejs.org/) | ||||
| -   [TypeScript](https://www.typescriptlang.org/) | ||||
| -   [MongoDB/mongoose](http://mongoosejs.com/) | ||||
| 
 | ||||
| and the other technologies we use | ||||
| 
 | ||||
| ### Getting Started | ||||
| 
 | ||||
| Clone the Repository: | ||||
| 
 | ||||
| ```bash | ||||
| git clone https://github.com/fosscord/fosscord-api | ||||
| cd discord-server | ||||
| ``` | ||||
| 
 | ||||
| #### Install (dev)dependencies: | ||||
| 
 | ||||
| ```bash | ||||
| npm install | ||||
| npm install --only=dev | ||||
| ``` | ||||
| 
 | ||||
| #### Starting: | ||||
| 
 | ||||
| ``` | ||||
| npm start | ||||
| ``` | ||||
| 
 | ||||
| #### Debugging: | ||||
| 
 | ||||
| **Vscode:** | ||||
| The Launch file configuration is in ``./vscode/launch.json``, | ||||
| so you can just debug the server by pressing ``F5`` or the ``> Launch Server`` button | ||||
| The Launch file configuration is in `./vscode/launch.json`, | ||||
| so you can just debug the server by pressing `F5` or the `> Launch Server` button | ||||
|  | ||||
							
								
								
									
										740
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										740
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										18
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								package.json
									
									
									
									
									
								
							| @ -1,12 +1,13 @@ | ||||
| { | ||||
| 	"name": "fosscord-api", | ||||
| 	"name": "@fosscord/api", | ||||
| 	"version": "1.0.0", | ||||
| 	"description": "This repository contains the HTTP API Server", | ||||
| 	"main": "index.js", | ||||
| 	"main": "dist/Server.js", | ||||
| 	"types": "dist/Server.d.ts", | ||||
| 	"scripts": { | ||||
| 		"test": "jest", | ||||
| 		"test:watch": "jest --watch", | ||||
| 		"start": "npm run build:util && npm run build && node dist/", | ||||
| 		"start": "npm run build:util && npm run build && node dist/start", | ||||
| 		"build": "tsc -b .", | ||||
| 		"build:util": "tsc -b ./node_modules/fosscord-server-util/", | ||||
| 		"postinstall": "npm i github:fosscord/fosscord-server-util && patch-package" | ||||
| @ -15,14 +16,21 @@ | ||||
| 		"type": "git", | ||||
| 		"url": "git+https://github.com/fosscord/fosscord-api.git" | ||||
| 	}, | ||||
| 	"keywords": [], | ||||
| 	"author": "", | ||||
| 	"keywords": [ | ||||
| 		"discord", | ||||
| 		"fosscord", | ||||
| 		"fosscord-api", | ||||
| 		"discord open source", | ||||
| 		"discord-open-source" | ||||
| 	], | ||||
| 	"author": "Fosscord", | ||||
| 	"license": "ISC", | ||||
| 	"bugs": { | ||||
| 		"url": "https://github.com/fosscord/fosscord-api/issues" | ||||
| 	}, | ||||
| 	"homepage": "https://github.com/fosscord/fosscord-api#readme", | ||||
| 	"dependencies": { | ||||
| 		"@fosscord/fosscord-server-util": "github:fosscord/fosscord-server-util", | ||||
| 		"@types/jest": "^26.0.22", | ||||
| 		"bcrypt": "^5.0.0", | ||||
| 		"body-parser": "^1.19.0", | ||||
|  | ||||
| @ -13,21 +13,21 @@ import { BodyParser } from "./middlewares/BodyParser"; | ||||
| import { Router } from "express"; | ||||
| import fetch from "node-fetch"; | ||||
| 
 | ||||
| export interface DiscordServerOptions extends ServerOptions {} | ||||
| export interface FosscordServerOptions extends ServerOptions {} | ||||
| 
 | ||||
| declare global { | ||||
| 	namespace Express { | ||||
| 		interface Request { | ||||
| 			// @ts-ignore
 | ||||
| 			server: DiscordServer; | ||||
| 			server: FosscordServer; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| export class DiscordServer extends Server { | ||||
| 	public options: DiscordServerOptions; | ||||
| export class FosscordServer extends Server { | ||||
| 	public options: FosscordServerOptions; | ||||
| 
 | ||||
| 	constructor(opts?: Partial<DiscordServerOptions>) { | ||||
| 	constructor(opts?: Partial<FosscordServerOptions>) { | ||||
| 		// @ts-ignore
 | ||||
| 		super({ ...opts, errorHandler: false, jsonBody: false }); | ||||
| 	} | ||||
|  | ||||
							
								
								
									
										52
									
								
								src/index.ts
									
									
									
									
									
								
							
							
						
						
									
										52
									
								
								src/index.ts
									
									
									
									
									
								
							| @ -1,33 +1,19 @@ | ||||
| process.on("uncaughtException", console.error); | ||||
| process.on("unhandledRejection", console.error); | ||||
| 
 | ||||
| import "missing-native-js-functions"; | ||||
| import { config } from "dotenv"; | ||||
| config(); | ||||
| import { DiscordServer } from "./Server"; | ||||
| import cluster from "cluster"; | ||||
| import os from "os"; | ||||
| const cores = os.cpus().length; | ||||
| 
 | ||||
| if (cluster.isMaster && process.env.production == "true") { | ||||
| 	console.log(`Primary ${process.pid} is running`); | ||||
| 
 | ||||
| 	// Fork workers.
 | ||||
| 	for (let i = 0; i < cores; i++) { | ||||
| 		cluster.fork(); | ||||
| 	} | ||||
| 
 | ||||
| 	cluster.on("exit", (worker, code, signal) => { | ||||
| 		console.log(`worker ${worker.process.pid} died, restart worker`); | ||||
| 		cluster.fork(); | ||||
| 	}); | ||||
| } else { | ||||
| 	var port = Number(process.env.PORT); | ||||
| 	if (isNaN(port)) port = 1000; | ||||
| 
 | ||||
| 	const server = new DiscordServer({ port }); | ||||
| 	server.start().catch(console.error); | ||||
| 
 | ||||
| 	// @ts-ignore
 | ||||
| 	global.server = server; | ||||
| } | ||||
| export * from "./Server"; | ||||
| export * from "./middlewares/"; | ||||
| export * from "./schema/Ban"; | ||||
| export * from "./schema/Channel"; | ||||
| export * from "./schema/Guild"; | ||||
| export * from "./schema/Invite"; | ||||
| export * from "./schema/Message"; | ||||
| export * from "./util/Captcha"; | ||||
| export * from "./util/Config"; | ||||
| export * from "./util/Constants"; | ||||
| export * from "./util/Event"; | ||||
| export * from "./util/instanceOf"; | ||||
| export * from "./util/Event"; | ||||
| export * from "./util/instanceOf"; | ||||
| export * from "./util/Member"; | ||||
| export * from "./util/RandomInviteID"; | ||||
| export * from "./util/String"; | ||||
| export * from "./util/User"; | ||||
| export { check as checkPassword } from "./util/passwordStrength"; | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| import { Authentication } from "./Authentication"; | ||||
| import { GlobalRateLimit } from "./GlobalRateLimit"; | ||||
| 
 | ||||
| export { Authentication, GlobalRateLimit }; | ||||
| export * from "./GlobalRateLimit"; | ||||
| export * from "./Authentication"; | ||||
| export * from "./BodyParser"; | ||||
| export * from "./CORS"; | ||||
| export * from "./ErrorHandler"; | ||||
| export * from "./RateLimit"; | ||||
|  | ||||
							
								
								
									
										33
									
								
								src/start.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/start.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,33 @@ | ||||
| process.on("uncaughtException", console.error); | ||||
| process.on("unhandledRejection", console.error); | ||||
| 
 | ||||
| import "missing-native-js-functions"; | ||||
| import { config } from "dotenv"; | ||||
| config(); | ||||
| import { FosscordServer } from "./Server"; | ||||
| import cluster from "cluster"; | ||||
| import os from "os"; | ||||
| const cores = os.cpus().length; | ||||
| 
 | ||||
| if (cluster.isMaster && process.env.production == "true") { | ||||
| 	console.log(`Primary ${process.pid} is running`); | ||||
| 
 | ||||
| 	// Fork workers.
 | ||||
| 	for (let i = 0; i < cores; i++) { | ||||
| 		cluster.fork(); | ||||
| 	} | ||||
| 
 | ||||
| 	cluster.on("exit", (worker, code, signal) => { | ||||
| 		console.log(`worker ${worker.process.pid} died, restart worker`); | ||||
| 		cluster.fork(); | ||||
| 	}); | ||||
| } else { | ||||
| 	var port = Number(process.env.PORT); | ||||
| 	if (isNaN(port)) port = 1000; | ||||
| 
 | ||||
| 	const server = new FosscordServer({ port }); | ||||
| 	server.start().catch(console.error); | ||||
| 
 | ||||
| 	// @ts-ignore
 | ||||
| 	global.server = server; | ||||
| } | ||||
| @ -0,0 +1 @@ | ||||
| export {}; | ||||
| @ -16,7 +16,7 @@ export default { | ||||
| 	setAll: Config.setAll, | ||||
| }; | ||||
| 
 | ||||
| export interface RateLimit { | ||||
| export interface RateLimitOptions { | ||||
| 	count: number; | ||||
| 	timespan: number; | ||||
| } | ||||
| @ -62,8 +62,8 @@ export interface DefaultOptions { | ||||
| 			}; | ||||
| 			routes: { | ||||
| 				auth?: { | ||||
| 					login?: RateLimit; | ||||
| 					register?: RateLimit; | ||||
| 					login?: RateLimitOptions; | ||||
| 					register?: RateLimitOptions; | ||||
| 				}; | ||||
| 				channel?: {}; | ||||
| 				// TODO: rate limit configuration for all routes
 | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| { | ||||
| 	"include": ["src/**/*.ts"], | ||||
| 	"include": ["src/**/*.ts", "src/test/rethink_test.ts.disabled"], | ||||
| 	"compilerOptions": { | ||||
| 		/* Visit https://aka.ms/tsconfig.json to read more about this file */ | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Flam3rboy
						Flam3rboy