I'm having a hard time setting up the replication between PouchDB and Sync Gateway.
I tried to follow Couchbase's blog post, but I wasn't successfull, either.
I'm building an Ionic application with angular-pouchdb and ng-pouchdb.
Here's what I got figured out so far:
every time I call pouchCollection it either creates a new database with the given name, or gives you a reference of the already created database;
the Sync Gateway is responsible for authorization of each document. I'm running it now with the GUEST user enabled, with "admin_channels": ["*"], so everyone should be able to access everything, right?
CORS should be enable, since both the app and the server are running on the same machine (localhost)
to get replication in both ways, I should use db.sync(URL) (angular-pouchdb), where URL is something like http://localhost:4984/prospect/ (and prospect could be the DB name)
Here's my Sync Gateway config.json file:
{
"log": ["CRUD", "REST+", "Access"],
"facebook": {"register": true},
"CORS": {
"Origin": ["http://localhost:8100"],
"LoginOrigin": ["http://localhost:8100"],
"Headers": ["Content-Type"],
"MaxAge": 17280000
},
"databases": {
"prospect": {
"server": "walrus:",
"users": {
"GUEST": {"disabled": false, "admin_channels": ["*"]}
},
"sync":
`
function(doc, oldDoc) {
channel("everything");
}
`
}
}
}
Here's my Ionic code:
app.controller('MyCtrl', function($scope, pouchCollection) {
$scope.students = pouchCollection('students');
var URL = 'http://localhost:4984/prospect/';
$scope.students.$db.replicate.sync(URL);
// ...list the array in the view
}
Whenever I try to make the replication work, I get the following in the console when running for the first time:
GET http://localhost:4984/prospect/_local/jeOaLtKGemQWDpNAPzorJQ%3D%3D?_nonce=1442271117949 404 (Not Found)xhRequest # pouchdb.js:641625.module.exports # pouchdb.js:6435ajax # pouchdb.js:604824.module.exports # pouchdb.js:6211ajax # pouchdb.js:989(anonymous function) # pouchdb.js:994ajaxPromise # pouchdb.js:993(anonymous function) # pouchdb.js:1241(anonymous function) # pouchdb.js:1069979 # pouchdb.js:10760(anonymous function) # pouchdb.js:7659(anonymous function) # pouchdb.js:764679 # pouchdb.js:1076068.Checkpointer.getCheckpoint # pouchdb.js:9407(anonymous function) # pouchdb.js:10076
pouchdb.js:6416 GET http://localhost:4984/prospect/_local/2_QcxPjLD.zmtOXa7VM8Gw%3D%3D?_nonce=1442271117953 404 (Not Found)xhRequest # pouchdb.js:641625.module.exports # pouchdb.js:6435ajax # pouchdb.js:604824.module.exports # pouchdb.js:6211ajax # pouchdb.js:989(anonymous function) # pouchdb.js:994ajaxPromise # pouchdb.js:993(anonymous function) # pouchdb.js:1241(anonymous function) # pouchdb.js:1069979 # pouchdb.js:10760(anonymous function) # pouchdb.js:7659(anonymous function) # pouchdb.js:764679 # pouchdb.js:10760(anonymous function) # pouchdb.js:9408
pouchdb.js:6416 GET http://localhost:4984/prospect/_local/jeOaLtKGemQWDpNAPzorJQ%3D%3D?_nonce=1442271118095 404 (Not Found)xhRequest # pouchdb.js:641625.module.exports # pouchdb.js:6435ajax # pouchdb.js:604824.module.exports # pouchdb.js:6211ajax # pouchdb.js:989(anonymous function) # pouchdb.js:994ajaxPromise # pouchdb.js:993(anonymous function) # pouchdb.js:1241(anonymous function) # pouchdb.js:1069979 # pouchdb.js:10760(anonymous function) # pouchdb.js:7659(anonymous function) # pouchdb.js:764679 # pouchdb.js:10760updateCheckpoint # pouchdb.js:930368.Checkpointer.updateTarget # pouchdb.js:936868.Checkpointer.writeCheckpoint # pouchdb.js:9362finishBatch # pouchdb.js:9829
(index):28 The above 404 is totally normal. PouchDB is just checking if a remote checkpoint exists.
Since the last line says it is normal, I assume everything is fine.
When I run the app in the browser and in the emulator, Sync Gateway says things like:
2015-09-14T19:54:04.913-03:00 HTTP: #001: GET /prospect/?_nonce=1442271244612
2015-09-14T19:54:18.730-03:00 HTTP: #002: GET /prospect/?_nonce=1442271258729
...
2015-09-14T19:56:13.362-03:00 HTTP: #049: GET /prospect/_local/2_QcxPjLD.zmtOXa7VM8Gw==?_nonce=1442271373356
2015-09-14T19:56:13.376-03:00 HTTP: #050: PUT /prospect/_local/2_QcxPjLD.zmtOXa7VM8Gw==
To me, it looks like everything is working. But I can't get it to sync with the iOS emulator or in a different browser.
What am I missing?
For your Questions..
[2]: The * Star channel is the channel where every document is automatically added to that channel. Example, a guest user will be granted the * star channel where that gives you the open ended access so any user that gets * (star) will be able to see everything in the system.
[3]: You do not need to enable CORS as sync gateway is running on the same domain as your webapp. Enabling CORS allows web apps to access resources on other domains rather than the origin domain.
The LoginOrigin list protects access to the _session and _facebook endpoints.
[4]: To replicate your data, within the app.js file you would define a URL variable for sync, like:
var SYNC_GATEWAY_URL = 'http://127.0.0.1:4984/prospect/';
Related
I have a package which contains static files I want to reuse among applications. Based on https://webassets.readthedocs.io/en/latest/environment.html#webassets.env.Environment.load_path I came up with the following code snippet, to be used in each application's __init__.py (the shared package is loutilities):
with app.app_context():
# js/css files
asset_env.append_path(app.static_folder)
# os.path.split to get package directory
asset_env.append_path(os.path.join(os.path.split(loutilities.__file__)[0], 'tables-assets', 'static'))
but when ASSETS_DEBUG = False, this causes a ValueError exception for one of the files found in the package. (See https://github.com/louking/rrwebapp/issues/366 for detailed traceback -- this is possibly related to https://github.com/miracle2k/webassets/issues/387).
ValueError: Cannot determine url for /var/www/sandbox.scoretility.com/rrwebapp/lib/python2.7/site-packages/loutilities/tables-assets/static/branding.css
Changed code to use a url parameter which now works fine for ASSETS_DEBUG = False
asset_env.append_path(os.path.join(os.path.split(loutilities.__file__)[0], 'tables-assets', 'static'), '/loutilities')
however now when ASSETS_DEBUG = True, I see that the file failed to load in the javascript console
Failed to load resource: the server responded with a status of 404 (NOT FOUND) branding.css
Have worked around the Catch-22 using the inelegant code as follows, but wondering how to choose the append_path() url parameter which will work for both ASSETS_DEBUG = True or False.
with app.app_context():
# js/css files
asset_env.append_path(app.static_folder)
# os.path.split to get package directory
loutilitiespath = os.path.split(loutilities.__file__)[0]
# kludge: seems like assets debug doesn't like url and no debug insists on it
if app.config['ASSETS_DEBUG']:
url = None
else:
url = '/loutilities'
asset_env.append_path(os.path.join(loutilitiespath, 'tables-assets', 'static'), url)
One solution is to create a route for /loutilities/static, thus
# add loutilities tables-assets for js/css/template loading
# see https://adambard.com/blog/fresh-flask-setup/
# and https://webassets.readthedocs.io/en/latest/environment.html#webassets.env.Environment.load_path
# loutilities.__file__ is __init__.py file inside loutilities; os.path.split gets package directory
loutilitiespath = os.path.join(os.path.split(loutilities.__file__)[0], 'tables-assets', 'static')
#app.route('/loutilities/static/<path:filename>')
def loutilities_static(filename):
return send_from_directory(loutilitiespath, filename)
with app.app_context():
# js/css files
asset_env.append_path(app.static_folder)
asset_env.append_path(loutilitiespath, '/loutilities/static')
I am trying to schedule an R script to run, using rtweet to hit the Twitter API and then using RPOSTgreSQL to load the data into a table once a day.
I was able to successfully use taskscheduleR to create the task. However, when it runs I get an error that says...
<credentials> oauth_token, oauth_token_secret
---
Requesting token on behalf of user...
Error: API user token required. see http://rtweet.info/articles/auth.html for instructions
Execution halted
Here is my entire code with a few things masked due to API credentials and database info, passwords, etc
#load all packages
library(rtweet)
library(sqldf)
library(dplyr)
library("RPostgreSQL")
#connect to Twitter API
create_token(
app = "masked for stack",
consumer_key = "masked for stack",
consumer_secret = "masked for stack",
access_token = "masked for stack",
access_secret = "masked for stack")
## get user IDs of accounts following
followers=get_followers("masked for stack", n = 1000)
## lookup data on those accounts
followers_data=lookup_users(followers$user_id)
#add the date of the run
followers_data$date=Sys.Date()
#extract columns
twitter_followers=dplyr::select(followers_data,"date","screen_name","name","location","description","followers_count",
"friends_count","listed_count","statuses_count","favourites_count","verified")
# create a connection
# save the password that we can "hide" it as best as we can by collapsing it
pw <- {
"masked for stack"
}
# loads the PostgreSQL driver
drv <- dbDriver("PostgreSQL")
# creates a connection to the postgres database
# note that "con" will be used later in each connection to the database
con <- dbConnect(drv, dbname = "masked for stack",
host = "localhost", port = 5432,
user = "postgres", password = pw)
rm(pw) # removes the password
# writes df to the PostgreSQL database
dbWriteTable(con, "twitter_followers",
value = twitter_followers, append = TRUE, row.names = FALSE)
My code runs perfectly fine doing everything on my own manually. It seems that rtweet doesn't like getting ran by windows scheduler.
Any ideas? `
So after hours of digging I figured out that something was not working well with the scheduleR app. It may have been creating a task in windows scheduler that wouldn't run when my laptop was on AC power I'm not sure. Either way I did a workaround like this.
Created a text file and saved as a .bat extension with the following format:
"C:\Program Files\R\R-3.5.2\bin\x64\R.exe" CMD BATCH file_location.R
From there I scheduled in Windows scheduler. Make sure you go through all the options and don't choose a basic task. If you do a basic one you may not allow it to run on laptop battery power.
mngmt-users.properties file. The users are added in the file but when I try to run the localhost it says it's running then if I try to view the admin console it is redirecting to http://localhost:9990/error/index_win.html. That tells the server is running but I could not open admin console.
#
# Properties declaration of users for the realm 'ManagementRealm' which is the default realm
# for new installations. Further authentication mechanism can be configured
# as part of the <management /> in standalone.xml.
#
# Users can be added to this properties file at any time, updates after the server has started
# will be automatically detected.
#
# By default the properties realm expects the entries to be in the format: -
# username=HEX( MD5( username ':' realm ':' password))
#
# A utility script is provided which can be executed from the bin folder to add the users: -
# - Linux
# bin/add-user.sh
#
# - Windows
# bin\add-user.bat
#
#$REALM_NAME=ManagementRealm$ This line is used by the add-user utility to identify the realm name already used in this file.
#
# On start-up the server will also automatically add a user $local - this user is specifically
# for local tools running against this AS installation.
#
# The following illustrates how an admin user could be defined, this
# is for illustration only and does not correspond to a usable password.
#
#admin=2a0923285184943425d1f53ddd58ec7a
tejaswini=25ab658c2861b2e64783aaa9ba95c2e5
aswini#19=388ced81791ddb1760b83dc4ec8b7a61
saisana=ff39d778414ab12d84fc4fa7fdacb634
alekya=d72e9c90345ce4d9290c3a2728b3cd60
prasad=c6c7c67cf343f6862d3b77bae9f61d17
teju=28b9e55b314fd60855a7843b4455dbed
Screen shot of added user
May be u have tried to create specifically application user or management user when u ran the addUser utility,
please refer the below link for steps to register user
https://bgasparotto.com/add-user-wildfly
I am trying to connect with ejabberd server using strophe.js, but I got the following error:
POST http://localhost/http-bind/ 404 (Not Found)
Strophe.Bosh._processRequest.sendFunc # strophe.js:4614
Strophe.Bosh._processRequest # strophe.js:4626
Strophe.Bosh._throttledRequestHandler # strophe.js:4778
Strophe.Bosh._connect # strophe.js:4177Strophe.Connection.connect # strophe.js:2335
$scope.login # app.js:162
fn # VM165:4
Ic.(anonymous function).compile.d.on.f # angular.js:23411
$get.n.$eval # angular.js:15916
$get.n.$apply # angular.js:16016
(anonymous function) # angular.js:23416
n.event.dispatch # jquery-2.1.3.min.js:3
n.event.add.r.handle # jquery-2.1.3.min.js:3
strophe.js:2784 7
I have found that Skype some time use port 80, that was assigned to Apache server.This think may prevent the http-binding.After quit Skype, It works fine.
I have a web application which I test locally and deploy on EC2 instance
I am using local nginx configuration which looks like as
location /static/ { alias /home/me/code/p/python/myapp/static/;
# if asset versioning is used
if ($query_string) {
expires max;
}
} location /templates/ { alias /home/me/code/p/python/app/templates/;
# if asset versioning is used
if ($query_string) {
expires max;
}
}
On EC2 instance, the only thing that would change is the path, e.g.
/home/me/code/p/python/myapp/static/ to /User/ubuntu/code/p/python/myapp/static/
To make this happen I change the configuration to look like
~/code/p/python/myapp/static/
but this didn't work, it shows the path
/etc/nginx/~/code/p/python/myapp/static/
which is not right
Question
- Is it possible to include environment variables in nginx conf?
What I want
- Nginx conf, which can read variables on specific machines to create paths, so that I don't have to change it per machine and code is reusable
Thank you
Two ways of doing this:
As suggested above, symlinking is a really good way of making paths match on machines, while keeping code in one place. A symbolic link basically is an alias; if /link is a symlink for /file, when you ask for /link, you'll get /file.
ln -s /file /link
Using include statements. In nginx, you can include variables.conf;. E.g.
nginx.conf:
include variables.conf
...
http {
listen $port;
...
}
variables.conf:
set $foo "Something";
set $bar "Else";
set $port 80;