This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| POST /tokens HTTP/1.1\r\n | |
| Host: localhost:4443\r\n | |
| Content-Type: application/json\r\n | |
| Content-Length: ${length}\r\n | |
| token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 | |
| \r\n\r\n | |
| ${stringBody} | |
| \r\n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "use strict"; | |
| //Imports | |
| const http = require("http"); | |
| const url = require("url"); | |
| const queryString = require("querystring"); | |
| const StringDecoder = require("string_decoder").StringDecoder; | |
| // ports for the process | |
| const httpPort = 4443; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const handler = { | |
| // if path is localhost:3000/user | |
| user: (data, cb) => { | |
| const { | |
| method | |
| } = data; | |
| const allowedMethods = ["post", "get"]; | |
| if (allowedMethods.indexOf(method) !== -1) { | |
| handler._count[method](data, cb); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require("fs"); | |
| const zlib = require("zlib"); | |
| // create stream for compressing data | |
| const compressedDataStream = zlib.createDeflate(); | |
| // create a stream to write file to fs | |
| const writeStreamFile = fs.createWriteStream( | |
| __dirname + "/index-compressed.html" | |
| ); | |
| // reading file original file from disk |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const http = require("http"); | |
| const fs = require("fs"); | |
| const zlib = require("zlib"); | |
| const server = http.createServer(); | |
| server.on("request", (req, res) => { | |
| const data = "random string"; | |
| const encodingHeader = req.headers["accept-encoding"]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs=require('fs'); | |
| create = (dir, record, data, cb = () => {}) => { | |
| // checking if collection directory exists or not | |
| const isDir = fs.existsSync(path.resolve(`${__dirname}/../.data/${dir}`)) | |
| if (isDir) { | |
| // if yes let us write the file | |
| fs.writeFile(path.resolve(`${__dirname}/../.data/${dir}/${record}.json`), JSON.stringify(data), | |
| (err) => { | |
| if (err) cb(err); | |
| else cb(null, data); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs=require('fs'); | |
| const path=require('path'); | |
| fs.readdirSync(path.resolve('./.data')).forEach((dir) => { | |
| db[dir] = {}; | |
| fs.readdirSync(path.resolve('./.data/' + dir)).forEach((file) => { | |
| db[dir][file.split('.')[0]] = JSON.parse(fs.readFileSync(path.resolve('./.data/' + dir + '/' + | |
| file))); | |
| }) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const https = require('https'); | |
| const URL = require('url'); | |
| const queryString = require('querystring') | |
| ajax = (url, options = {}, cb) => { | |
| options = { | |
| method: 'get', | |
| body: null, | |
| ...options | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const express=require('express'); | |
| const jwt=require('jsonwebtoken'); | |
| const user=require('./user'); | |
| const key=require("./key"); | |
| const app=express(); | |
| app.use(require('body-parser').json()); | |
| app.use(function(req,res,next){ | |
| try{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require("path"); | |
| module.exports = { | |
| entry: "./src/index.js", | |
| mode: "development", | |
| output: { | |
| filename: "./main.js" | |
| }, | |
| devServer: { | |
| contentBase: path.join(__dirname, "dist"), |
OlderNewer