Monday 12 June 2017

node mssql preparestatment output identity id

I'm using https://www.npmjs.com/package/mssql

I'm using sql.PreparedStatement to do the insert and I would like to use the request.output('id', sql.Int) to get my identity id(auto increasing ID). But I'm getting null value.

query:

INSERT INTO queue (refid, name, channel) VALUES (@refid, @name, @channel)

If I use request.output('refid', sql.Int) it was able to get the refid.

If I use OUTPUT INSERTED.id the id will store in recordset as below:

<
  recordsets[[object]],
  recordset[<id:xx>],
  output<refid:123>,
  rowsAdected: [1],
  returnValue: 0
>

What I prefer is:

<
  recordsets[[object]],
  recordset[],
  output<id:999, refid:123>,
  rowsAdected: [1],
  returnValue: 0
>



via hendry91

NodeJS - Crytography (S.S.E.)

Someone can help me to do the inverted operation of this? http://www.paranoiaworks.mobi/sse/file_encryption_specifications.html

I have encrypted a file on Android with an app that uses this specification (the algorithm was AES-256). I want to decrypt the file using node-js, the crypto module only is not sufficient, because there is not the necessary functions to derive the key like the app did. There is some library that I can use to do that?

PS: I need to decrypt it using node-js and not using their app for desktop because it's a very sensible file and I need to work with it only on memory.

Thanks in advance.



via Murillo Brandão

Implement helmet-csp on individual routes

I'm creating a sample Express app to demonstrate Content-Security-Policy (CSP) headers and am trying to use helmet-csp.

All of the documentation for helmet-csp shows it used as standard third-party-middleware via app.use(csp({ ... })) - this adds the CSP headers to every route in my application, but I want to customize it on individual routes.

Sample App

var express = require('express');
var http = require('http');
var csp = require('helmet-csp');
var app = express();

app.use(csp({
    directives: {
        frameSrc: ["'none'"]
    }
}));

app.get('/', (request, response) => {
    response.send('hi, :wave: =]');
});

app.get('/frameable', (request, response) => {
    response.send('you can frame me!');
});

http.createServer(app).listen(80, (err) => {
    if (err) {
        return console.log('error', err);
    }
});

With the above, every route receives the CSP header:

Content-Security-Policy: frame-src 'none'

In the /frameable route, I would want to override this CSP header to be:

Content-Security-Policy: frame-src 'self'

Whenever I need/want to customize a header set by helmet-csp on a per-route basis, do I need to manually override them inside each app.get with a line such as:

response.setHeader('Content-Security-Policy', "frame-src 'self'");

Or is there a way to do this via helmet-csp itself?



via newfurniturey

Within Express, how can I add core modules to my package.json dependencies so I can require them in my js files?

I'm trying to use the core module 'connect' and, if I understand the situation correctly, express uses that module internally. I want to require it manually, and I've tried to insert it into my dependencies within my package.json file. Maybe I'm not installing it correctly with my git bash? I'm taking shots in the dark here, but here are my dependencies within the file.

"dependencies": {
"connect": "2.4.2",
"accepts": "~1.3.3",
"array-flatten": "1.1.1",
"content-disposition": "0.5.2",
"content-type": "~1.0.2",
"cookie": "0.3.1",
"cookie-signature": "1.0.6",
"debug": "2.6.7",
"depd": "~1.1.0",
"encodeurl": "~1.0.1",
"escape-html": "~1.0.3",
"etag": "~1.8.0",
"finalhandler": "~1.0.3",
"fresh": "0.5.0",
"merge-descriptors": "1.0.1",
"methods": "~1.1.2",
"on-finished": "~2.3.0",
"parseurl": "~1.3.1",
"path-to-regexp": "0.1.7",
"proxy-addr": "~1.1.4",
"qs": "6.4.0",
"range-parser": "~1.2.0",
"send": "0.15.3",
"serve-static": "1.12.3",
"setprototypeof": "1.0.3",
"statuses": "~1.3.1",
"type-is": "~1.6.15",
"utils-merge": "1.0.0",
"vary": "~1.1.1"

}



via Forrest Carlton

gulp-replace from template and project source and merge into single file

Alright, one for the ages. The issue is I am trying to merge the structure from multiple sources into a single one. One of my sources is from the template.html which contains the base structure for index.html -source-. I trying to find a solution that replaces html block data from the source -index.html- body tag into the destination -template.html- lastly create a new merged document which outputs to -dest-.

File structure that is as follows:

  • public
  • ---assets
  • ------template.html
  • ---src
  • ------app.js
  • ------index.html
  • ------main.css
  • ---dist
  • ------merged.html

I am using npm package gulp-replace (but open to other packages).

var gulp = require('gulp');
var htmlreplace = require('gulp-html-replace');
var copycat = require('gulp-copycat');

gulp.task('default', function() {
    // create a watch task
    gulp.task('default', function() {
        gulp.src('assets/template.html')
            .pipe(htmlreplace({
                'cssInline': {
                    src: gulp.src('sheetgmail/main.css'),
                    tpl: '<style>%s</style>'
                },
                'body': gulp.src('sheetgmail/index.html'),
                'headscript': {
                    src: null,
                    tpl: '%s'
                },
                'js': {
                    src: gulp.src('sheetgmail/app.js'),
                    tpl: "<script type='text/javascript'>%s</script>"
                },
            }, {
                keepUnassigned: false,
                keepBlockTags: true,
                resolvePaths: false
            }))
            .pipe(gulp.dest('dist/'));
    });
});



via Isaiah Monroe Davis

couldn't node-gyp rebuild (ERROR binding.cc : No such)

I'm trying node-gyp rebuild but get fatal error.

c1xx : fatal error C1083: Cannot open source file: '..\src\binding.cc': No 
such
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` 
fail
gyp ERR! stack     at ChildProcess.onExit 
(C:\Users\Admin\AppData\Roaming\npm\no
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit 
(internal/child_proces
gyp ERR! System Windows_NT 10.0.15063
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" 
"C:\\Users\\Admin\\AppDat
gyp ERR! cwd C:\Users\Admin
gyp ERR! node -v v6.11.0
gyp ERR! node-gyp -v v4.0.0
gyp ERR! not ok

I use Python 2.7 node-gyp -v v4.0.0 node -v v6.11.0

and node-gyp configure will warn with missing input binding.cc.



via L.seonbeen

Wordpress API with Express

Is it possible to make an external http get request from Wordpress API using express?

Let's say I want to make a get request to http://demo.wp-api.org/wp-json/wp/v2/posts - This are a list of posts from wordpress.

Sample:

router.get('/posts', function(req, res){
     I should make an external http request here from wordpress api
     ("http://demo.wp-api.org/wp-json/wp/v2/posts")

     Then I want to display the response as json
}



via Sherwin Ablaña Dapito