How to work with those fancy modern js frameworks #67
-
Hello, im trying to use this as captcha for my contact form in AstroJS. And i have a few questions
maybe i should search AstroJS support, let me know. This is my code for the api route: import type { APIRoute } from "astro";
import mosparo from '@mosparo/api-client';
let client = new mosparo.Client('http://localhost:8080', 'mykeys', 'mykeys', {});
export const post: APIRoute = async ({ request }) => {
const data = await request.formData();
const name = data.get("name");
const email = data.get("email");
const message = data.get("message");
const mosparoSubmitToken = data.get("_mosparo_submitToken");
const mosparoValidationToken = data.get("_mosparo_validationToken");
client.verifySubmission({name, email, message}, mosparoSubmitToken, mosparoValidationToken).then((verificationResult) => {
if (verificationResult.isSubmittable()) {
console.log('ok?')
} else {
console.log('not ok')
}
});
}; |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Thank you very much for your questions.
router.post('/', function (req, res, next) {
let client = new mosparo.Client(
process.env.MOSPARO_HOST,
process.env.MOSPARO_PUBLIC_KEY,
process.env.MOSPARO_PRIVATE_KEY,
{
httpsAgent: new https.Agent({
rejectUnauthorized: false
})
}
);
let formData = req.body;
try {
let validationPromise = client.validateSubmission(formData);
validationPromise.then((verificationResult) => {
if (verificationResult.isSubmittable()) {
res.redirect('/successful');
} else {
res.redirect('/error');
}
});
} catch (e) {
console.log(e);
}
});
Kind reagrds, zepich |
Beta Was this translation helpful? Give feedback.
-
Hello @zepich , sorry for that dumb questions. I just looked into it a bit more, i found this message on the docker server side, cna this have something todo with it?: |
Beta Was this translation helpful? Give feedback.
-
That was not a dumb question. We have to document it better, so we will adjust the README.md of the JavaScript API client to make it more understandable. As far as I can tell, the message you saw is not the reason for the issue. It sounds like there is an issue with the connection. It means the backend does not connect to the mosparo host, or a connection issue happened (like it tries to communicate by SSL, but there is no SSL set up). Is the backend running also in a Docker image? If yes, then maybe the two containers have no connection (between each other). It is also possible that there is an issue with the Docker image with the JavaScript API since I didn't test the library with the Docker image. I will test it tomorrow. Kind regards, zepich |
Beta Was this translation helpful? Give feedback.
-
Hi @zepich This is totally on me. I should have known that my platform blocks Thanks for the amazing work you have done to this project! |
Beta Was this translation helpful? Give feedback.
Hi @xttlegendapi
That was not a dumb question. We have to document it better, so we will adjust the README.md of the JavaScript API client to make it more understandable.
As far as I can tell, the message you saw is not the reason for the issue. It sounds like there is an issue with the connection. It means the backend does not connect to the mosparo host, or a connection issue happened (like it tries to communicate by SSL, but there is no SSL set up). Is the backend running also in a Docker image? If yes, then maybe the two containers have no connection (between each other).
It is also possible that there is an issue with the Docker image with the JavaScript API since I didn't test the l…