Saturday, 1 December 2018

Nodejs won't set cookie for React CRA application even with proxy

I have a nodejs/express + React CRA application, and I'm trying to set a cookie from nodejs. The server is on port 4001, so in my React application's project.json I have "proxy": "http://localhost:4001" set, but the cookie still won't get set in the browser.

I've tested it in production mode as well, with the React application being served from nodejs directly and it all works fine there.

Here is how I am setting the cookie. I've tried several different combinations of options here and they all have the same result.

res.cookie('jwt', token, {
    httpOnly: false,
    sameSite: false,
    signed: false,
    secure: false,
    encode: String
});
res.header('Access-Control-Allow-Credentials', 'true');



from Nodejs won't set cookie for React CRA application even with proxy

Firebase database storing into sqlite database with some properties unchanged

Okay so my app database is completely stored on firebase, and my app updates its database every day.

What procedure i used to follow everytime during updating the data:

  1. Drop the current sqlite table
  2. Create the table again
  3. Fill in the data

This used to work perfectly, imagine a row is deleted so as i drop the whole table and rewrite the whole thing, the deleted row also get technically deleted from the local sqlite,But now there is a slight change in the table, there is a column, say "viewed" which stores if the particular row data is viewed or not, "true" or "false" (String)

Now if i drop the data while updating, it'll lose this column properties. Then i thought of using UPDATE in sqlite and update the data of the columns of each row, but then there might be instances when a particular column is no more in the firebase, but if i do this, it will remain in my local database. (I mean that data is not edited but deleted). So how can i overcome this ?

Old Table :

db.execSQL("CREATE TABLE IF NOT EXISTS appdata_videos (id TEXT, link TEXT, title TEXT, subcode TEXT)");

New Table :

db.execSQL("CREATE TABLE IF NOT EXISTS appdata_videos (id TEXT, link TEXT, title TEXT, subcode TEXT, viewed TEXT)");

P.S. I am using firebase single time listener as i need to update data only once daily.

I used to run this function everytime i wanted to clear the database :

public void clearDB()
    {
        db.execSQL("DROP TABLE IF EXISTS subCodes");
        db.execSQL("CREATE TABLE IF NOT EXISTS subCodes (id TEXT, dbName TEXT, subName TEXT, tagline TEXT, pref INTEGER, hasInterviewQuestions TEXT, hasVideos TEXT, hasCodes TEXT)");
        db.execSQL("DROP TABLE IF EXISTS appdata_codes");
        db.execSQL("CREATE TABLE IF NOT EXISTS appdata_codes (id TEXT, question TEXT, code TEXT, tag TEXT, subcode TEXT, imglink TEXT, xlink TEXT)");
        db.execSQL("DROP TABLE IF EXISTS appdata_videos");
        db.execSQL("CREATE TABLE IF NOT EXISTS appdata_videos (id TEXT, link TEXT, title TEXT, subcode TEXT)");
        db.execSQL("DROP TABLE IF EXISTS appdata_interviewquestions");
        db.execSQL("CREATE TABLE IF NOT EXISTS appdata_interviewquestions (id TEXT, subcode TEXT, html TEXT)");
    }



from Firebase database storing into sqlite database with some properties unchanged

using python virtual env in R

I am using 'rPython' package for calling python within R but I am unable to make R refer to my python's virtual environment.

In R, I have tried using

system('. /home/username/Documents/myenv/env/bin/activate')

but after running the above my python library path does not change (which I check via python.exec(print sys.path)). When I run

python.exec('import nltk')

I am thrown the error:

Error in python.exec("import nltk") : No module named nltk

although it is there in my virtual env.

I am using R 3.0.2, Python 2.7.4 on Ubuntu 13.04.

Also, I know I can change the python library path from within R by using

python.exec("sys.path='\your\path'")

but I don't want this to be entered manually over and over again whenever a new python package is installed.

Thanks in advance!



from using python virtual env in R