Categories
Mastering Development

Adding headers to my fetch request causes CORS failure (express)

I’m using the cors library and have the following settings on my server (running on localhost:8000): cors({ // Allow requests from these origins :: Access-Control-Allow-Origin origin: `http:localhost:8001`, // Allow certain headers :: Access-Control-Allow-Headers allowedHeaders: [ “Origin”, “X-Requested-With”, “Content-Type”, “Accept”, “Authorization” ], // Allows us to send cookies cross origin :: Access-Control-Allow-Credentials credentials: true, // Allow […]

Categories
Development

Sending Cookie back with a fetch(GET) after a fetch(POST) request

I need to set up a cookie in browser after sending a POST request in a javascript(js) and try to ask the browser to send this new-set cookie back in a subsequent fetch GET request. Here is my js script: fetch(authorise_url, { method: ‘POST’, headers: { ‘Accept’: ‘application/json’, ‘Content-Type’: ‘application/json’ }, credentials: ‘include’, body: JSON.stringify({ […]

Categories
Development

Fetch() Response Null

For some reason I cannot really push all the failed/undetectable urls (pstart is a link, tmp is the directory name) into an array after the fetch fails on a link. I even added in an additional catch after the response! Can someone please help me out with figuring out how to get around this? This […]

Categories
Development

get csrf token in react native

I have built django server to manage my data, then I have desktop react app where I can create new users/login/post data, it works flawless, It is based on csrf token verification and there is no problem with that. However I have also react-native app which is supposed to let user log in, and GET […]

Categories
Development

Clearing request cache on IE11 – POST getting saved as a GET

This question is very similar to this post except specific to clearing the cache in the IE11 browser. No matter how I clear my history/cache (clearing history, Network Tab > clear cache, Network tab > always refresh from server) when I submit a new request, I am seeing the response with this message Received (from […]

Categories
Development

Querying for a local state variable doesn’t immediately return a result

I’m querying for my local variable isLeftSidebarOpen and I thought that it should immediately return result without loading state. isLeftSidebarOpen is initialized when ApolloClient is created. const data = { isLeftSidebarOpen: false, }; const initializeCache = cache => { cache.writeData({ data }); }; const cache = new InMemoryCache(); const client = new ApolloClient({ link: new […]

Categories
Development iOS

Get cookies from axios local requests

I’m having a problem to receive cookies in server side (PHP). when I send Axios request to the server (local.project.com:8000) with these headers the server saves the cookie and sends it back to front Response cookies. then when I’m making another request I’m not getting back the cookie in PHP debugmode.. but when making the […]

Categories
Development Plugins

gatsby-source-graphql does not seem to pass cookie header, how to solve?

How to pass Cookie headers from gatsby-source-graphql? I’m using the gatsby-source-graphql (https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-graphql) and recently had to implement AWS Cloudfront Signed Cookies to authorise users to acccess a private staging environment, for this reason the requests to the graphql endpoint, handled by the plugin, need to have the cookie in the request header, which I do […]

Categories
Development

How to fix CORS error: request doesn’t pass access control check?

I have express.js server: import express from ‘express’; import cors from ‘cors’; import bodyParser from ‘body-parser’; import mongoose from ‘mongoose’; import helmet from ‘helmet’; import config from ‘./config/config.js’; import authRoutes from ‘./routes/auth.js’; import userRoutes from ‘./routes/user.js’; mongoose.connect(config.mongoUri, { useNewUrlParser: true }); mongoose.connection.on(‘error’, () => { throw new Error(`unable to connect to database: ${config.mongoUri}`); }); const […]

Categories
Development

How to load a service in React before rendering components?

If I have a service that calls some REST API resources, but in order to get the URL of that API need to perform another REST call locally from the same deployed site and read that URL from a config file. I made that call inside the constructor of the service, and set a local […]