We see an error, it says: Missing parameter ?callbackDomain.
So let's add it to our url.
http://18.198.170.188/this-is-hollywood-we-are-calling-you?callbackDomain=google.com
Now we have another error:
Could not connect to your endpoint at https://google.com/add ?a=304200972448620530645069240248291931164 &b=32662422308137202040109741665765070137
So the service will call /add endpoint with a
and b url-parameters. Each of them contains BigInt.
And I assume we should add them together and send it back to the server.
So let's write simpe server that adds two big numbers together.
{
"name": "level10",
"version": "1.0.0",
"description": "Service for sum a and b",
"main": "app.js",
"scripts": {
"start": "node app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "sierikov",
"license": "MIT",
"dependencies": {
"express": "^4.17.1"
}
}
So I have only express. Now we need app.js file.
Init the express and take port to run on from the enviroment:
const express = require("express");
const app = express();
const port = process.env.PORT || 443;
Activate listening:
app.listen(port, () => {
console.log(`Server is running on port: ${port}`);
});
Define endpoint wich tage a and b and send
the anwser as string back to the server.
app.get("/add", function (req, res) {
let a = req.query?.a
let b = req.query?.b
res.send(`${a + b}`);
console.log(`Got a: ${a}, b: ${b}`);
});
But, we have trouble that JS will round our numbers in exponential form.
app.get("/add", function (req, res) {
let a = BigInt(req.query?.a);
let b = BigInt(req.query?.b);
res.send(`${a + b}`);
console.log(`Got a: ${a}, b: ${b}`);
});
So we need to wrap our a and b with BigInt
constructor.
Let's check if this works.
npm starthttp://localhost:443/add?a=2&b=46Here you can download the full source code.
We cannot give just IP adress of our network as callbackDomain
We need to get one.
I have found three services to expose our local Node.js app to the world:
Install: npm install -g localtunnel
Start the app: npm start
Expose: lt --port 443
We get perfect-swan-72.loca.lt and will pass it to the website.
Calling https://perfect-swan-72.loca.lt/add?a=27850060344159548346000990344376658296 &b=89380160078435183319458195098204483639 Congratulations, you returned the correct sum 27850060344159548346000990344376658296 + 89380160078435183319458195098204483639 === 117230220422594731665459185442581141935 Find the next level at lets-go-to-the-movies.mp4
So our result url will be:
http://18.198.170.188:80/lets-go-to-the-movies.mp4
If we go to this url we will see Level 11 ( task / solution )