scripting / feedlandInstall

Instructions for setting up a FeedLand server.
GNU General Public License v3.0
3 stars 1 forks source link

New feature: the config.js option, new daveappserver release #9

Open scripting opened 1 year ago

scripting commented 1 year ago

Good morning feedlandinstallers! ;-)

I made a change to FeedLand today to create another option for configuring FeedLand at startup.

The config.js option

Now, if you place a config.js file in the same folder as feedland.js, we will load that instead of config.json, via a JavaScript require call.

That means you can have code run to create the object, which allows it to be part of a more complex hosting environment.

So for example, config.js could contain this code:

module.exports = {
   myName: "Bull Mancuso",
   myMotto: "Not on your life."
   }

Then after feedland.js loads config will have two new values -- myName and myMotto.

Obviously you can have any code generate that object. You could get it from a file you access over the net or get info from a database or the web server, or OS, or where ever. It's more power than config.json, and more complexity.

For small installations however, config.json is the way to go.

New daveappserver

As you may know I've been working this week on creating a new version of Drummer that does not depend on Twitter identity and uses HTTPS.

In doing this work, I had to make changes to daveappserver, which FeedLand also uses. So there is a chance of breakage here. Please update your feedland installation to get the new daveappserver, v0.6.10, and report any problems.

If present, I would expect them to be in creating new accounts, logging on to existing accounts, and any operation that involves identity (subscribing to a feed, for example).

I'm going back to work on Drummer today, but will keep my eye on this repo as well.

I feel things are winding up nicely now. And thanks for your help with FeedLand. :smile:

chriszarate commented 1 year ago

This is great! FYI, I don't yet see daveappserver v0.6.10 as published:

https://www.npmjs.com/package/daveappserver?activeTab=versions

scripting commented 1 year ago

@chriszarate --

Sorry about that -- I'm juggling too many balls.

Please try again.

chriszarate commented 1 year ago

There it is! I'll get it tested shortly.

troutcolor commented 1 year ago

I seem to have lost my categories in my feedland install

What I did: Quick visual check of my Feedland in my browse Stopped feedland npm update node feedland

Back to Browser and the categories had gone, no tabs on my river and none to select in the 'tagger'

Should not take long to put them back, but thogh you might like to know

I could not see anything on in the console.

Cheers John

scripting commented 1 year ago

@troutcolor -- thanks for letting me know.

You can go ahead and add back the categories. I may have seen something like that happen, it's in the area of the program where I would expect problems given that it was recently updated to have its identity system replaced.

btw, it's also important to look for errors in the console for the server as well as the browser. you're actually running two pieces of software here that are communicating with each other.

troutcolor commented 1 year ago

Thanks, I added them back to settings, which seems to have got nearly all of then sorted out. I went through and added the ones that seemed missing ( a lot of All ones). I really line the tagging interface where you can keep the dialog open and go through the feeds. Super feature.

scripting commented 1 year ago

@troutcolor -- that feature was 20 years in development. I tried out all kinds of interfaces, and that was the one that I actually used. All of the others I tried over the years might have been nice to look at and seem simple enough, but it wasn't long before i got lazy and stopped using them.

chriszarate commented 1 year ago

Hi @scripting! After testing, I don't think this is working as expected.

Now, if you place a config.js file in the same folder as feedland.js, we will load that instead of config.json, via a JavaScript require call.

The code change introduced to daveappserver looks for config.js in its own folder. If not found, it looks in the parent directory. When we use feedland as a project dependency (following the setup instructions), that means it looks for config.js in these two places, and not alongside feedland.js:

[project root]
config.js
feedland.js
└─ node_modules
   └─ [looks for config.js here second]
   └─ daveappserver
      ├─ appserver.js
      └─ [looks for config.js here first]

This is an annoying problem to solve. An "ok" solution is to use the current working directory, which is usually set to the project root, especially if you launch your application using an npm script (e.g., npm start):

const configPath = require("path").join(process.cwd(), "config.js");
configJs = require (configPath);

This won't work if you launch the application directly from another folder (node ~/Projects/my-project/feedland.js) but it might be good enough with documentation.

Another option is to use an library like app-root-path that handles most edge cases, usually by walking the tree upwards until it finds the project root.

Let me know if I can help further to resolve this issue and many thanks for working on this!

Lastly, a quick aside on these updates:

Please update your feedland installation to get the new daveappserver, v0.6.10, and report any problems.

Because daveappserver is a dependency of feedland and the feedland package was not updated to point to v.0.6.10 of daveappserver, updating via NPM has no effect. In order to test this, I needed to add this overrides section to my package.json:

  "overrides": {
    "feedland": {
      "daveappserver": "0.6.10"
    }
  }

Ideally, future updates should be accompanied by an update to the feedland package as well.

scripting commented 1 year ago

@chriszarate

the first thing is a mistake. it should go up two levels not one. the code had not been tested, i will fix that.

i'm also open to other approaches, the first priority should be getting you up and running.

here's an idea -- put a config.json in the same directory as feedland.js, with one entry in it, pathToConfigFile, basically a config-level redirect. then was start the whole thing over, process it differently if it has a .js or .json extension.

does that work?

I have to look into this some more

For some reason when it reads config.json it doesn't have to do any of this weird stuff it's doing with config.js.

I bet there's a way to work around this.

There's a requireFromString package I use in another product.

I think that's how we'll do it.

chriszarate commented 1 year ago

For some reason when it reads config.json it doesn't have to do any of this weird stuff it's doing with config.js.

That's because the string ref config.json resolves to the current working directory (process.cwd()), while ./config.js resolves to the directory of the current file (in this case, node_modules/daveappserver).

This mostly works, but does have the same issue noted above:

This won't work if you launch the application directly from another folder (node ~/Projects/my-project/feedland.js) but it might be good enough with documentation.

But that issue is navigable and not worth spending too much time on, in my opinion.

scripting commented 1 year ago

@chriszarate

When you get a chance, please check out the changes I made to daveappserver.

I was able to fix the problem by loading config.js into memory, if it is present, and run it through the require-from-string package.

I have used it in other projects, and it's proven solid.

And now there is no confusion about where config.js goes -- into the folder with feedland.js. No need to try different folders.

To get the new version npm update in the folder with feedland.js. I took care of updating the feedland module so you should get all the new bits.

chriszarate commented 1 year ago

Confirmed, works great! Thanks, Dave. Onward to more testing....