Meteor URL prefix - meteor

I have an issue with Meteor 0.6.6.2
When I deploy on the production. I have to following error :
/home/gt/webapps/meteor/bundle/programs/server/boot.js:185
}).run();
^
Error: a route URL prefix must begin with a slash
at _.extend.declare (packages/routepolicy/routepolicy.js:95)
at new StreamServer (packages/livedata/stream_server.js:23)
at new Server (packages/livedata/livedata_server.js:980)
at Package (packages/livedata/server_convenience.js:10)
at packages/livedata.js:3909:4
at packages/livedata.js:3920:3
at /home/gt/webapps/meteor/bundle/programs/server/boot.js:154:10
at Array.forEach (native)
at Function._.each._.forEach (/home/gt/webapps/meteor/bundle/programs/server/node_modules/underscore/underscore.js:79:11)
at /home/gt/webapps/meteor/bundle/programs/server/boot.js:81:5
My root_url is set to :
export ROOT_URL='http://sub.mydomain.com'
I had not problem with older version of Meteor.

I found the error. I debugged the paths in routepolicy.js ( in /bundle/programs/server/app
line 56 with console.info(urlPrefix) ) and found that my export ROOT_URL was not correct.
For some reason, my export command (export ROOT_URL='http://mydomain.com' was not successfull and it was still ROOT_URL='mydomain.com')
See :
Github issue : https://github.com/meteor/meteor/issues/1404

Here's what I'm doing to support namespaced routes (using Iron Router):
lib/namespace.js contains:
Router._mapOld = Router.map;
Router.map = function(namespace, cb) {
if (_.isFunction(namespace)) {
cb = namespace;
return Router._mapOld.call(this, cb);
}
namespace = namespace.replace(/\/+$/, '');
var that = this;
that._routeOld = that.route;
that.route = function(name, options) {
if (!_.isString(options.path)) {
throw new Error(
'Namespaced routes must have a path specified as a string.');
}
return that._routeOld.call(that, name, _.extend(options, {
path : namespace + options.path
}));
};
var ret = Router._mapOld.call(that, cb);
that.route = that._routeOld;
return ret;
};
Then you can do:
Router.map(function() {
// Add routes normally with no prefix
});
Router.map('/prefix', function() {
// All routes you add here will be prefixed with /prefix
});

Do you use middleware, or server side routes somewhere? If so, all path params for middleware must begin with a /, so change some/path to /some/path. It started to be important in one of recent versions.
ROOT_URL does not have to end with a /, by the way – yours is correct.

Related

Module not found : Can't resolve 'fs' in Electron/Nextjs

I'm trying to check if a file exist and if not, starts to download in my eletron app.
The error i have is the next one :
error - ./node_modules/electron/index.js:1:0
Module not found:can't resolve 'fs'
null
Where i use the function
mainWindow.webContents.session.on(
'will-download',
.....
ipcMain.on('folder', (event, arg) => {
if (arg === 'check') {
const folder =
app.getPath('userData') +
'\\Local Storage\\' +
privateHash.split('.')[0];
var file = searchFile(folder);
if (file != null) {
OpenApp(
folder + '\\' + file,
meeting,
token,
company,
avatar,
scene
);
} else {
sending a message to the renderer to download the file
}
The searchFile function is something like this :
const searchFile = (folder) => {
var fs = require('fs');
var files = fs.readdirSync(folder.split('.')[0]);
....
I have looked in stackOverflow to similar problems and try their solutions, but for me it doesn't work.If somebody can help it will be great.
I put nodeIntegration, in package.json browser..fs:false,path:false,os:false..,i add to next.config.js webpack config , nothing is working for me
you are probably trying to run server side code on the browser, that is very common, i would suggest that you follow the calls stack and figure out where that code is being run a browser environment and and conditionally skip, EX
if (typeof window === 'undefined') {
// do server side stuff ex. you can run your function here.
} else {
// if you are in a client environment do nothing and return
return;
}

Accounts.onLogin throws session not found error

The LoggedInUser works well as it is suppose but whenever the app starts and the URL is queried like trying to login or navigate to any other URL, the Accounts.onLogin throws the below error. I don't know what could be the reason.
var LoggedInUser = FlowRouter.group({
name: 'currentUser', triggersEnter: [function () {
if (!Meteor.loggingIn() || !Meteor.userId()) {
var currentRoute = FlowRouter.current();
if (!currentRoute.route.name === 'home') {
console.log(currentRoute.path);
Session.set('redirectAfterLogin', currentRoute.path);
}
FlowRouter.go('home');
}
}]
});
Accounts.onLogin(function () {
let redirect = Session.get('redirectAfterLogin');
if (redirect) {
if (redirect != 'home') {
FlowRouter.go(redirect);
}
}
});
Error on cmd console
I20171003-18:28:44.913(1)? Exception in onLogin callback: ReferenceError: Session is not defined
I20171003-18:28:44.919(1)? at lib/routes/routes.js:30:18
I20171003-18:28:44.921(1)? at runAndHandleExceptions (packages\callback-hook.js:152:24)
I20171003-18:28:44.926(1)? at packages\callback-hook.js:159:12
I20171003-18:28:44.931(1)? at packages/accounts-base/accounts_server.js:164:5
I20171003-18:28:44.934(1)? at [object Object]._.extend.each (packages\callback-hook.js:128:15)
I20171003-18:28:44.938(1)? at AccountsServer.Ap._successfulLogin (packages/accounts-base/accounts_server.js:163:21)
I20171003-18:28:44.943(1)? at AccountsServer.Ap._attemptLogin (packages/accounts-base/accounts_server.js:353:10)
I20171003-18:28:44.946(1)? at [object Object].methods.login (packages/accounts-base/accounts_server.js:530:21)
I20171003-18:28:44.949(1)? at packages\check.js:128:16
I20171003-18:28:44.953(1)? at [object Object].EVp.withValue (packages\meteor.js:1135:15)
The onLogin function you are using needs the Session package according to the following line :
let redirect = Session.get('redirectAfterLogin');
The error in the console states than the Session package can not be found. Please make sure of the following:
Meteor Session is installed. If not please install it with:
meteor add Session
in your terminal in your project folder.
Session is imported in the file you want to use it, if not please add at the top of your file :
import { Session } from 'meteor/session'

usage example for chokidar in Meteor to prevent Error: Meteor code must always run within a Fiber

The code below gives me the Error: 'Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.'
import chokidar from 'chokidar';
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
const Plates = new Mongo.Collection('plates');
var path = '~/Documents/dev/lpr/test';
var watcher = chokidar.watch(path, {
ignored: /(^|[\/\\])\../,
persistent: true
});
watcher.on('add', path => {
console.log(`DEBUG: File ${path} has been added`);
Plates.insert({
path,
})
});
The Meteor documentation (https://guide.meteor.com/using-npm-packages.html#wrap-async) suggests using Meteor.wrapAsync to solve this issue but I don't understand how to apply in this case?
e.g. below returns 'TypeError: watcherFiber.on is not a function'
var watcherFiber = Meteor.wrapAsync(chokidar.watch(path, {
ignored: /(^|[\/\\])\../,
persistent: true
}));
watcherFiber
.on('add', path => {
console.log(`DEBUG: File ${path} has been added`);
Plates.insert({
path,
})
});
The error text points you to the correct way to do that.
It should be like this:
watcher.on('add', Meteor.bindEnvironment(path => {
console.log(`DEBUG: File ${path} has been added`);
Plates.insert({
path,
});
}));

How to specify the location of kml file when using geoxml3 parser with meteor js

I have been trying to parse a kml file using the geoxml3 parser. The geoxml3.js file is put in the public folder. The parser is working fine if I put the kml file inside the public folder.
geoXml.parse('doc.kml'); // this is working fine
But how can I make it work if the kml file is located somewhere else, say in the 'uploads' folder outside the public folder. I have tried,
geoXml.parse(uploadPath+'/doc.kml');
but this is not working. How should I specify the file path ? I can't put the kml files in the public folder as any change inside the folder will make the page refresh.
Please help me out.
Haven't tried this one, but Assets.getText() may be what you're looking for. The documentation
specifies that you pass it a file path relative to your private directory.
Well, could not resolve the path issue. Assets.getText() is dependent on the private folder and also it doesn't stop the server from restart. But found an alternative solution, where you can upload the file to any folder within your project app and read from it.
// On client side
Meteor.call('getKmlString', kml_file_name, function(error, kml_string) {
if (error) {
console.log('ERROR in getting kml string');
console.log(error);
} else {
console.log('GOT Kml String');
geoXml.parseKmlString(kml_string);
}
});
// On server side
Meteor.startup(function() {
// code to run on server at startup
return Meteor.methods({
getKmlString: function(kml_file_name) {
var content = '';
var fs = Npm.require('fs');
var encoding = encoding || 'binary';
var chroot = Meteor.chroot || 'uploads';
var path = chroot + (path ? '/' + path + '/' : '/');
var content = fs.readFileSync('../../../../../' + path + kml_file_name, "utf-8", function read(err, data) {
if (err) {
throw err;
}
});
return content;
},
});
});

How can I use NodeJS modules in Meteor?

In a NodeJS application ,I have finished some modules,Now I want to use them in Meteor,What should I do?
For example,there is a file 'hello.js',content:
require('url');// In here,require other modules
function sayHi(name){
console.log("Hi "+ name);
}
exports.sayHi = sayHi;
How do I use 'say Hi' in meteor?
when I do this:
if (Meteor.isServer) {
Meteor.startup(function () {
var require = __meteor_bootstrap__.require;
var index = require('./hello');
hello.syaHi('Ec');})}
Errors is:
app/index.js:1
require();
^
ReferenceError: require is not defined
at app/index.js:1:1
at /home/huyinghuan/workspace/NodeJs/myMeteorJS/testrequire/.meteor/local/build/server/server.js:113:21
at Array.forEach (native)
at Function._.each._.forEach (/usr/lib/meteor/lib/node_modules/underscore/underscore.js:79:11)
at run (/home/huyinghuan/workspace/NodeJs/myMeteorJS/testrequire/.meteor/local/build/server/server.js:99:7)
I think, you have to install/copy your module into projectdir/.meteor/local/build/server/node_modules which is a link to /usr/local/meteor/lib/node_modules. I tried this with the node.js module tracer and it worked. You have to copy your files into this directory every time you updated your meteor installation.
Also, it looks like Npm.require() is the right way to require node modules now.
Update, I had to install my module into .meteor/local/build/programs/server/node_modules as well as use Npm.require.
Here's a package which makes it a lot easier to use NPM packages inside Meteor:
https://github.com/meteorhacks/npm
example usage:
if (Meteor.isClient) {
getGists = function getGists(user, callback) {
Meteor.call('getGists', user, callback);
}
}
if (Meteor.isServer) {
Meteor.methods({
'getGists': function getGists(user) {
var GithubApi = Meteor.npmRequire('github');
var github = new GithubApi({
version: "3.0.0"
});
var gists = Async.runSync(function(done) {
github.gists.getFromUser({user: 'arunoda'}, function(err, data) {
done(null, data);
});
});
return gists.result;
}
});
}

Resources