Socket
Socket
Sign inDemoInstall

express-js-mod

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-js-mod - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

3

express-js-mod/express-js-mod.js

@@ -99,2 +99,5 @@ import { MessageValue } from "helpers/messageTranslation";

// do stuff here with chunked data
if (this.outboundResponse.hasChunkResponse) {
return this.outboundResponse.sendChunkResource(val1);
}
break;

@@ -101,0 +104,0 @@ case MessageValue.responseComplete:

@@ -21,2 +21,3 @@ // https://blog.stevenlevithan.com/archives/parseuri

});
Object.freeze(parseQuery);
export default parseQuery;

@@ -0,1 +1,2 @@

import Resource from "Resource";
export default class Response {

@@ -5,2 +6,4 @@ headers = [];

body = '';
data = null;
position;
status(status) {

@@ -20,2 +23,36 @@ this.requestStatus = status;

}
sendResource(path) {
try {
this.headers.push('Content-Type');
this.headers.push('application/json');
this.data = new Resource(path.slice(1));
this.position = 0;
return {
headers: [
"Content-type", "text/plain",
"Content-length", this.data.byteLength,
],
body: true,
};
}
catch (err) {
return {
status: 404,
headers: [
"Content-type", "text/plain",
],
body: "file not found",
};
}
}
get hasChunkResponse() {
return this.data;
}
sendChunkResource(value) {
if (this.position >= this.data.byteLength)
return;
const chunk = this.data.slice(this.position, this.position + value);
this.position += chunk.byteLength;
return chunk;
}
build() {

@@ -22,0 +59,0 @@ return {

2

package.json
{
"name": "express-js-mod",
"version": "1.0.2",
"version": "1.0.3",
"description": "An express like router for moddable sdk and XS javascript engine",

@@ -5,0 +5,0 @@ "main": "./express-js-mod/express-js-mod.js",

@@ -33,7 +33,16 @@

We can send resources as responses in routes and callbacks like...
let app = new Express(Server)
app.get('/home', function(req,res) {
res.sendResource(new Resource("index.html"))
})
let port = 80 // 80 is the default port
app.listen(port)
## Todo
- [ ] Tests, tests, more tests
- [ ] Query Params
- [ ] Inbound Data Handling
- [x] Query Params
- [x] Inbound Data Handling
- [ ] Post route test

@@ -43,4 +52,5 @@ - [ ] Put/Patch route test

- [ ] Support Hash of Routes using app.route()
- [ ] Chunked Buffer handling
- [ ] res.file()
- [ ] Inbound Chunked Buffer handling
- [ ] Outbound Chunked Buffer handling
- [x] res.sendResource()
- [ ] mime-types

@@ -47,0 +57,0 @@ - [ ] buffers

@@ -125,3 +125,6 @@ import { MessageValue } from "helpers/messageTranslation";

case MessageValue.responseFragment:
// do stuff here with chunked data
// do stuff here with chunked data
if (this.outboundResponse.hasChunkResponse) {
return this.outboundResponse.sendChunkResource(val1)
}
break;

@@ -128,0 +131,0 @@ case MessageValue.responseComplete:

@@ -27,2 +27,4 @@ // https://blog.stevenlevithan.com/archives/parseuri

Object.freeze(parseQuery)
export default parseQuery

@@ -5,2 +5,4 @@ export default class Response {

body: string = ''
data: any = null;
position: any;
status(status: Number){

@@ -21,2 +23,39 @@ this.requestStatus = status

sendResource(resource:any, contentType: string){
try {
this.headers.push('Content-Type');
this.headers.push(contentType)
this.data = resource;
this.position = 0;
return {
headers: [
"Content-type", this.headers,
"Content-length", this.data.byteLength,
],
status: this.requestStatus,
body: true,
};
} catch(err) {
return {
status: 404,
headers: [
"Content-type", "text/plain",
],
body: "file not found",
};
}
}
get hasChunkResponse(){
return this.data
}
sendChunkResource(value: any) {
if (this.position >= this.data.byteLength)
return;
const chunk = this.data.slice(this.position, this.position + value);
this.position += chunk.byteLength;
return chunk;
}
build(){

@@ -23,0 +62,0 @@ return {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc