Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const server = http.createServer();
- endResponse(str){
- this.response.write(str);
- this.response.end("");
- },
- dieIfBadAccess(request)
- {
- var body = '';
- var self = this;
- request.on('data', function (data) {
- body += data;
- // 1e6 === 1 * Math.pow(10, 5) === 1 * 100000 ~~~ 100kb
- if (body.length > 1e5) {
- // FLOOD ATTACK OR FAULTY CLIENT, NUKE REQUEST
- request.connection.destroy();
- self.responseEND();//maybe not needed
- }
- });
- return body;
- },
- setResponseVariable(resp){
- this.responseGLOBAL = resp;
- },
- echo (content){
- if (!this.responseGLOBAL.finished) this.responseGLOBAL.write(content); else c(content);
- },
- responseError(str) { this.output = { status: "error", response:str }; this.responseEcho(); this.responseEND(); },
- responseSuccess(str){ this.output = { status: "success", response:str }; this.responseEcho(); this.responseEND(); },
- error (num, extra) { this.responseError(this.MessageCodes(num,extra)); },
- success(str) { this.responseSuccess(str); },
- responseEcho(str){ this.echo( JSON.stringify(this.output) ); },
- responseEnded:false,
- responseEND(){ this.responseGLOBAL.end(""); },
- start_server()
- {
- const self = this;
- server.on('request', function (request, response) {
- try {
- if (request.url == '/favicon.ico') return;
- var data = self.dieIfBadAccess(request);
- if (!('act' in query)) {
- this.responseError("no action");
- }
- else {
- var { headers, method, url } = request;
- await this.create_responserPage();
- }
- }
- catch (exc) {
- c(exc);
- }
- });
- server.listen(this.Server_Port, host);
- console.log(`Server running at ${this.Server_Url}`);
- },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement