Learning locker statement forwarding

280 Views Asked by At

I have learning locker running locally in my computer and I would like to show the statements in an external website, this is easy with the dashboards as there is the option to have a link that can be put into an iframe, but when I do the same with the part of the statements it says that the ip (learning locker) has blocked the access, so I tried with the statement forwarding to a node.js server created as:

const http = require('http');
const { parse } = require('querystring');
const server = http.createServer((req, res) => {
    if (req.method === 'POST') 
    {
        
        console.log(req);  
    } 
});
server.listen(8090);

But when I look at the req (Incomming Message) and it appears as empty, I has some fields as the headers:

headers:
   { accept: 'application/json, text/plain, */*',
     'content-type': 'application/json',
     'x-experience-api-version': '1.0.0',
     'user-agent': 'axios/0.18.1',
     'content-length': '532',
     host: 'IP_ADDRESS:8090',
     connection: 'close' },
  rawHeaders:
   [ 'Accept',
     'application/json, text/plain, */*',
     'Content-Type',
     'application/json',
     'X-Experience-API-Version',
     '1.0.0',
     'User-Agent',
     'axios/0.18.1',
     'Content-Length',
     '532',
     'Host',
     'IP_ADDRESS:8090',
     'Connection',
     'close' ],

But there are no body and nothing related with the statement.

1

There are 1 best solutions below

0
On

by default, nodejs server do not parse POST body. You can try using https://www.npmjs.com/package/body-parser middleware with express.js framework

var express = require('express')
var bodyParser = require('body-parser')
 
var app = express()
 
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
 
// parse application/json
app.use(bodyParser.json())
 
app.use(bodyParser.urlencoded({ extended: false }))

app.use(function (req, res) {
  res.setHeader('Content-Type', 'text/plain')
  res.write('you posted:\n')
  res.end(JSON.stringify(req.body, null, 2))
})

app.listen(8090, function(error){ 
  if(error) {
    throw error
  }
})