Notion API call in Nextjs app hangs when deployed on Vercel - axios

I have an API that adds customer data to our CRM system and also some information to our Notion board.
It involves three external API calls.
Two to our CRM system, and one to our Notion board.
The first two work flawlessly. However, when it gets to the Notion API call, the call just hangs when deployed to production.
Here's the codeblock
console.log("Notion api should trigger now")
axios({
method: 'POST',
url: 'https://api.notion.com/v1/pages/',
headers: {
Authorization: `Bearer ${notionKey}`,
'Content-Type': 'application/json',
'Notion-Version': '2021-05-13',
},
timeout: 10000,
data: data,
}).then((response)=>{
console.log(response)
}).catch((error) => {
console.log(error);
postToSlack({ error_loc: 'notionLead', data: data });
postToSlack({
error_msg: error.response.data,
});
});
These are the only logs that I get from Vercel
Link to the whole file
https://gist.github.com/SSardorf/e0421d04d1f9857cb3f2d934d92a5e9f#file-ac_contact-js-L76-L86

Related

Rack protection remote token blocking access

I have a vuejs frontend appplication and an api using Sinatra ruby. It took some reading and understanding but I got it working fine locally (respectively on localhost:3000 and localhost:9292).
All routes except for a few are accessible only with a jwt.
The frontend uses axios for the requests.
// general configuration of axios get request
const getData = axios.create({
baseURL: import.meta.env.VITE_API_ROOT,
withCredentials: true,
method: 'get',
headers: {
'Content-Type': 'application/json',
},
})
and this is invoked like so:
getData.get(`user/a/checkmail/${form.email}`)
.then((response) => {
// cut because irrelevant here
On the API side, I have this:
# app.rb
register Sinatra::Cors
set :allow_origin, "https://www.lafindumois.app http://localhost:3000 https://lafindumois.app/ www.lafindumois.app lafindumois.app"
set :allow_headers, "Access-Control-Allow-Origin,content-type,__authorization__,Access-Control-Allow-Credentials"
set :allow_methods, "GET, HEAD, POST, DELETE"
set :jwt, ''
# config.ru
use Rack::Protection, permitted_origins: ["http://localhost:3000", "http://127.0.01:3000","https://www.lafindumois.app","https://lafindumois.app www.lafindumois.app lafindumois.app"], :except => :session_hijacking
If I comment out the line use Rack::Protection in config.ru, it is all working fine. Therefore, I don't think this is a CORS problem.
But with this line, the browser returns a cors error and the logs state:
WARN -- : attack prevented by Rack::Protection::RemoteToken

Dio is making a lot of request when debugging with debugger

I am debugging the API call to server for authentication. When I debug in Android Studio and step into the request, network shows multiple requests being made. While not debugging, the request are happening only once, but during debugging with breakpoints, there are mutltitude of requests being made.
These are the base options and interceptors being used. The interceptor also confirms that multiple requests are being made for some reason.
Dio get dio => Dio(BaseOptions(
baseUrl:
'${getIt<ConfigReader>().baseURL}${getIt<ConfigReader>().apiPath}',
contentType: Headers.jsonContentType,
responseType: ResponseType.json,
headers: {
'Accept': Headers.jsonContentType,
},
))
..interceptors.add(LogInterceptor());
How can I resolve the issue?

How to Properly Set Permissions for a Custom Strapi Plugin

Strapi Version: 4.1.5
Operating System: Debian GNU/Linux 9
Database: PostgreSQL 13
Node Version: v14.16.0
NPM Version: 6.14.11
Yarn Version: v1.22.5
Hi everyone, I can’t seem to find consistent information on how to use permissions with a custom plugin in Strapi. I want to make an endpoint available to my front-end (Next.JS) application, but only when the front-end application has authenticated as a user and using the JWT that is returned from authenticating with Strapi. I keep getting a 401 returned.
Here’s what I’m doing:
I used this page to set up authentication in Strapi. I have a user created in Strapi, and from the front-end, I can authenticate and it returns a JWT token. When I set up collection types to only be accessible with the “authenticated” role, I can access those collection types in the api using this JWT token. So all of that works. The problem is that I can’t get this to work with my custom plugin, and I’m not sure why. I still get a 401 error instead.
Here’s how I set up the permissions:
Based on this page, I initially tried to leverage the isAuthenticated permission that the Users & Permissions plugin provides:
{
method: "GET",
path: "/progress",
handler: "memberProgress.getProgress",
config: {
policies: ['plugins::users-permissions.isAuthenticated']
},
},
Unfortunately, this did not work. The server raised an error, saying that this could not be found. So back on the document linked above, I decided to take the approach of creating my own gloabl permission. I created src/policies/is-authenticated.js with the following contents:
module.exports = (policyContext, config, { strapi }) => {
if (policyContext.state.user) { // if a session is open
// go to next policy or reach the controller's action
return true;
}
return false; // If you return nothing, Strapi considers you didn't want to block the request and will let it pass
};
Then, I modified my plugin’s route as follows:
{
method: "GET",
path: "/progress",
handler: "memberProgress.getProgress",
config: {
policies: ['global::is-authenticated']
},
},
This is all based on that document I linked to. Unfortunately, this still does not work. It seems to find the permission (server doesn’t raise an error about it), but when I try to access my plugin’s endpoint with the JWT token, I just get a 401 error.
Here is how I’m trying to access the endpoint on the front-end:
// VERIFIED, auth works and I get the expected jwt
const strapiAuth = await strapiApiAuth();
if ( strapiAuth && strapiAuth.hasOwnProperty("jwt") ) {
try {
const response = await axios.get(
`${process.env.STRAPI_BACKEND_URL}/member-progress/progress?year=2022&name=&pageSize=10&page=1`,
{
headers: {
Accept: "application/json",
Authorization: `Bearer ${strapiAuth.jwt}`
},
timeout: 500,
}
);
console.log(response);
} catch (error) {
// This is where I land with the 401 error
console.log(error);
}
}
Strapi check if you have a valid jwt by default with "authenticated" role, but you must mark the permission to your custom endpoint in "Settings→User & Permission Plugin→Roles" of admin panel also.

Connecting Aurelia with backend API

Context: I'm starting a new project for my company. It's been many years since I've done some web development and decided to build it using the latest platforms (so I'm a still new to all of this).
Current stack:
Aurelia frontend (running on localhost:9000)
Backend REST API using ExpressJS (running on localhost:8000)
PostGreSQL database running on AWS, providing data for the backend
Question: I can't seem to connect my frontend with my backend properly.
Here is my code:
import {inject} from "aurelia-framework";
import {HttpClient} from "aurelia-http-client";
#inject(HttpClient)
export class Login {
constructor(httpClient){
this.http = httpClient;
}
signIn() {
const url = 'http://localhost:8000/api/user/demo/test';
this.http
.get(url)
.then(data => {
console.log("data");
console.log(data);
})
.catch(error => {
console.log('Error getting ' + url);
console.log(error);
});
};
}
This always end up in the catch block, with a "response: ProgressEvent"
If I put the url in the browser I get a proper JSON:
{"status":"success","data":[],"message":"Retrieved ALL users"}
The code above only works for 'local' content, i.e. localhost:9000. As soon as I need content from somewhere else I get this error. What am I missing?
I think that CORS is not allowing you to access localhost:8000 from localhost:9000. To solve this, you should enable your ExpressJS server to accept CORS requests from localhost:9000 (or all hosts using a wildcard "*").
Look into these resources:
https://enable-cors.org/server_expressjs.html
https://github.com/expressjs/cors
Or search Google for 'expressJS cors'.

LDAP authentication fails on ripple and actual device but not on browser

I'm trying to get an authorization token for an Ionic App from a LDAP service in a remote server.
I can get the auth token when I run the Ionic App in the browser with the command ionic serve and when I use Postman,
BUT it takes lot of time and eventually fails when I debug using ripple for the App or when I test on the phone or tablet.
The error says:
status: 503
statusText: Service Unavailable
data: html code from http://s3.amazonaws.com/heroku_pages/error.html
var deferred = $q.defer();
var req = {
method: 'GET',
url: 'http://host:port/adap?bind=token',
headers: {
Authorization: 'Basic <username>:<password>'
}
};
$http( req )
.then(function(data, status, headers, config) {
console.log(data);
deferred.resolve(data.data);
})
.catch(function(data) {
console.error(data.data);
deferred.reject(err);
});
return deferred.promise;
Does anybody have some hint about this issue?
Thanks in advance
For what you say the service is available, so the problem must be in the app side.
Check IP tables, and check ripple's proxy and set it to none.