@benzene/server
Advanced tools
Comparing version 0.1.2 to 0.1.4
# @benzene/server | ||
## 0.1.3 | ||
### Patch Changes | ||
- fc4a5f9: Use querystring instead of @polka/url | ||
## 0.1.2 | ||
@@ -4,0 +10,0 @@ |
@@ -6,2 +6,3 @@ import { GraphQL } from '@benzene/core'; | ||
path?: string; | ||
query?: Record<string, string>; | ||
}, res: ServerResponse) => void; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createHandler = void 0; | ||
const core_1 = require("@benzene/core"); | ||
const querystring_1 = require("querystring"); | ||
const readBody_1 = require("./readBody"); | ||
const url_1 = __importDefault(require("@polka/url")); | ||
function createHandler(gql, options = {}) { | ||
@@ -22,8 +19,8 @@ function sendResponse(res, result) { | ||
return function handler(req, res) { | ||
const idx = req.url.indexOf('?'); | ||
if (options.path && | ||
(req.path || url_1.default(req, true).pathname) !== options.path) | ||
(req.path || (idx !== -1 ? req.url.substring(0, idx) : req.url)) !== | ||
options.path) | ||
return sendResponse(res, { status: 404, body: 'not found', headers: {} }); | ||
readBody_1.readBody(req, async (err, body) => { | ||
if (err) | ||
return sendErrorResponse(res, err); | ||
readBody_1.readBody(req, async (body) => { | ||
let context; | ||
@@ -39,3 +36,3 @@ if (options.context) | ||
error.message = `Context creation failed: ${error.message}`; | ||
sendErrorResponse(res, error); | ||
return sendErrorResponse(res, error); | ||
} | ||
@@ -45,3 +42,6 @@ sendResponse(res, await core_1.runHttpQuery(gql, { | ||
httpMethod: req.method, | ||
queryParams: url_1.default(req, true).query || null, | ||
queryParams: req.query || | ||
(idx !== -1 | ||
? querystring_1.parse(req.url.substring(idx + 1)) | ||
: null), | ||
body, | ||
@@ -48,0 +48,0 @@ headers: req.headers, |
@@ -5,2 +5,2 @@ /// <reference types="node" /> | ||
body?: any; | ||
}, cb: (err: any, body: Record<string, any> | string | null) => void): void; | ||
}, cb: (body: Record<string, any> | string | null) => void): void; |
@@ -6,16 +6,14 @@ "use strict"; | ||
// If body has been parsed as a keyed object, use it. | ||
if ('body' in req && typeof req.body === 'object') { | ||
return cb(null, req.body); | ||
} | ||
if ('body' in req && typeof req.body === 'object') | ||
return cb(req.body); | ||
if (req.method === 'GET') | ||
return cb(null, null); | ||
return cb(null); | ||
const oCtype = req.headers['content-type']; | ||
// Skip requests without content types. | ||
if (!oCtype) | ||
return cb(null, null); | ||
return cb(null); | ||
let rawBody = ''; | ||
req.on('data', (chunk) => (rawBody += chunk)); | ||
req.on('error', (err) => cb(err, null)); | ||
req.on('end', () => cb(null, rawBody)); | ||
req.on('end', () => cb(rawBody)); | ||
} | ||
exports.readBody = readBody; |
{ | ||
"name": "@benzene/server", | ||
"version": "0.1.2", | ||
"version": "0.1.4", | ||
"description": "Fast and simple GraphQL Server for Node.js", | ||
@@ -12,3 +12,7 @@ "author": "Hoang Vo (https://hoangvvo.com)", | ||
], | ||
"repository": "git+https://github.com/hoangvvo/benzene.git", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/hoangvvo/benzene.git", | ||
"directory": "packages/server" | ||
}, | ||
"bugs": { | ||
@@ -21,9 +25,10 @@ "url": "https://github.com/hoangvvo/benzene/issues" | ||
"types": "dist/index.d.ts", | ||
"files": ["dist"], | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "mocha" | ||
"test": "uvu -r ts-node/register/transpile-only" | ||
}, | ||
"dependencies": { | ||
"@polka/url": "^1.0.0-next.11", | ||
"@benzene/core": "^0.2.0" | ||
@@ -30,0 +35,0 @@ }, |
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
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
7893
2
0
136
- Removed@polka/url@^1.0.0-next.11
- Removed@polka/url@1.0.0-next.28(transitive)