Skip to content

Commit aef22d6

Browse files
committed
[update] replacing deprecated require() with import statements
1 parent 5df0d21 commit aef22d6

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

‎README.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,12 +498,14 @@ example.js:
498498

499499
.. code-block:: js
500500
501+
import crypto from 'crypto';
502+
501503
function secret_key(r) {
502504
return process.env.SECRET_KEY;
503505
}
504506
505507
function create_secure_link(r) {
506-
return require('crypto').createHash('md5')
508+
return crypto.createHash('md5')
507509
.update(r.uri).update(process.env.SECRET_KEY)
508510
.digest('base64url');
509511
}
@@ -579,6 +581,8 @@ example.js:
579581

580582
.. code-block:: js
581583
584+
import crypto from 'crypto';
585+
582586
function authorize(r) {
583587
var signature = r.headersIn.Signature;
584588
@@ -596,7 +600,7 @@ example.js:
596600
597601
var args = r.variables.args;
598602
599-
var h = require('crypto').createHmac('sha1', process.env.SECRET_KEY);
603+
var h = crypto.createHmac('sha1', process.env.SECRET_KEY);
600604
601605
h.update(r.uri).update(args ? args : "");
602606
@@ -694,6 +698,8 @@ example.js:
694698

695699
.. code-block:: js
696700
701+
import crypto from 'crypto';
702+
697703
function authorize(r) {
698704
var signature = r.headersIn.Signature;
699705
@@ -702,7 +708,7 @@ example.js:
702708
return;
703709
}
704710
705-
var h = require('crypto').createHmac('sha1', process.env.SECRET_KEY);
711+
var h = crypto.createHmac('sha1', process.env.SECRET_KEY);
706712
707713
h.update(r.uri);
708714
@@ -1757,7 +1763,7 @@ example.js:
17571763

17581764
.. code-block:: js
17591765
1760-
var fs = require('fs');
1766+
import fs from 'fs';
17611767
var STORAGE = "/tmp/njs_storage"
17621768
17631769
function push(r) {

‎njs/http/authorization/auth_request.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import crypto from 'crypto';
2+
13
function authorize(r) {
24
var signature = r.headersIn.Signature;
35

@@ -15,7 +17,7 @@ function authorize(r) {
1517

1618
var args = r.variables.args;
1719

18-
var h = require('crypto').createHmac('sha1', process.env.SECRET_KEY);
20+
var h = crypto.createHmac('sha1', process.env.SECRET_KEY);
1921

2022
h.update(r.uri).update(args ? args : "");
2123

‎njs/http/authorization/request_body.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import crypto from 'crypto';
2+
13
function authorize(r) {
24
var signature = r.headersIn.Signature;
35

@@ -6,7 +8,7 @@ function authorize(r) {
68
return;
79
}
810

9-
var h = require('crypto').createHmac('sha1', process.env.SECRET_KEY);
11+
var h = crypto.createHmac('sha1', process.env.SECRET_KEY);
1012

1113
h.update(r.uri);
1214

‎njs/http/authorization/secure_link_hash.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import crypto from 'crypto';
2+
13
function secret_key(r) {
24
return process.env.SECRET_KEY;
35
}
46

57
function create_secure_link(r) {
6-
return require('crypto').createHash('md5')
8+
return crypto.createHash('md5')
79
.update(r.uri).update(process.env.SECRET_KEY)
810
.digest('base64url');
911
}

‎njs/http/complex_redirects.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var fs = require("fs");
1+
import fs from 'fs';
22
var DB = "/tmp/njs_resolv.db";
33

44
function open_db() {

‎njs/misc/file_io.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var fs = require('fs');
1+
import fs from 'fs';
22
var STORAGE = "/tmp/njs_storage"
33

44
function push(r) {

0 commit comments

Comments
 (0)