Comparing version 0.0.2 to 0.0.3
112
index.js
@@ -1,105 +0,31 @@ | ||
let contentType ={"Content-Type" : "application/json"} | ||
/* | ||
================== | ||
200 plus status | ||
================== | ||
*/ | ||
exports.sendJSON = function(req, res, data, resEnd=true){ | ||
// on succes | ||
res.writeHead(200, contentType); | ||
if(data){ | ||
res.write(JSON.stringify(data)); | ||
} | ||
if(resEnd){ | ||
res.end(); | ||
} | ||
var msg200 = require("./src/200"); | ||
var msg300 = require("./src/300"); | ||
var msg400 = require("./src/400"); | ||
var msg500 = require("./src/500"); | ||
var cookie = require("./src/cookie"); | ||
} | ||
exports.send200 = function(req, res, resEnd=true){ | ||
// 200 | ||
res.writeHead(200, contentType); | ||
if(resEnd){ | ||
res.end(); | ||
} | ||
} | ||
exports.sendJSON = msg200.sendJSON; | ||
exports.send200 = msg200.send200; | ||
/* | ||
====================== | ||
300 plus status | ||
====================== | ||
*/ | ||
exports.movedPermently = function(req, res, url, resEnd=true){ | ||
// redirect temporary | ||
res.writeHead(301,{Location: url } ); | ||
if(resEnd){ | ||
res.end(); | ||
} | ||
} | ||
exports.redirectTemporary = function(req, res, url, resEnd=true){ | ||
// redirect temporary | ||
res.writeHead(301,{Location: url } ); | ||
if(resEnd){ | ||
res.end(); | ||
} | ||
} | ||
exports.redirectPerment = function(req, res, url, resEnd=true){ | ||
// redirect perment | ||
res.writeHead(301,{Location: url } ); | ||
if(resEnd){ | ||
res.end(); | ||
} | ||
} | ||
exports.movedPermently = msg300.movedPermently; | ||
exports.redirectTemporary = msg300.redirectTemporary; | ||
exports.redirectPerment = msg300.redirectPerment; | ||
/* | ||
====================== | ||
400 plus status | ||
====================== | ||
*/ | ||
exports.send404 = msg400.send404; | ||
exports.send405 = msg400.send405; | ||
exports.send413 = msg400.send413; | ||
exports.send404 = function(req, res, resEnd=true){ | ||
// Requested page not availeble | ||
res.writeHead(404,"Resource not found", contentType); | ||
res.write(JSON.stringify({"data" : "Resource not found"})); | ||
if(resEnd){ | ||
res.end(); | ||
} | ||
} | ||
exports.send405 = function(req, res, resEnd=true){ | ||
// Method not supporetd ie. GET, POST others not supported | ||
res.writeHead(405,"Method not supported", contentType); | ||
res.write(JSON.stringify({"data" : "Method not supported"})); | ||
if(resEnd){ | ||
res.end(); | ||
} | ||
} | ||
exports.send500 = msg500.send500; | ||
exports.send413 = function(req, res, resEnd=true){ | ||
// Requesting for large data, not supported | ||
res.writeHead(413, "Request too large", contentType); | ||
res.write(JSON.stringify({"data" : "Request too large"})); | ||
if(resEnd){ | ||
res.end(); | ||
} | ||
} | ||
exports.getCookie = cookie.getCookie; | ||
exports.setCookie = cookie.setCookie; | ||
/* | ||
================== | ||
500 status | ||
================== | ||
*/ | ||
exports.send500 = function(req, res, err, resEnd=true){ | ||
// on error | ||
res.writeHead(500, "Internal error occured", contentType); | ||
res.write(JSON.stringify({"data" : "Internal error occured: " + err})); | ||
if(resEnd){ | ||
res.end(); | ||
} | ||
} | ||
{ | ||
"name": "http-msgs", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Node module to handle to HTTP status codes", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# http-msgs | ||
Node module to handle to HTTP status codes | ||
![verson](https://img.shields.io/badge/version-0.0.2-green.svg) | ||
![verson](https://img.shields.io/badge/version-0.0.3-green.svg) | ||
![License](https://img.shields.io/badge/License-MIT-yellowgreen.svg) | ||
@@ -60,2 +60,7 @@ | ||
## cookie | ||
``` | ||
httpMsgs.setCookie(req, res, cookieString, data, resEnd=true) | ||
httpMsgs.getCookie(req, res, curCookie); | ||
``` | ||
For more extensive study on read in this link [HTTP status](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7906
11
139
65
1