Nodejs Solid Server on mobile

Has anybody created (or attempted) a node.js solid server on a mobile device – android or IOS?

Somebody has created a node.js server that runs on Android, IOS and React. In theory it should be possible to bring the standard solid server on top of that and I’d like to try it, but has anybody tried it yet?

Even node-solid-server on node.js on termux counts, although this seems too heavy other than prototyping.

Why would I want that? In short so that my game/app can work without an internet connection and it will help with usability if my user doesn’t have to register for a solid pod (yes, I know everyone should have one, but they don’t yet). The long version probably deserves a separate topic in another category.

I know that the client library has some caching (not sure of the details), so that may be an alternative with code changes. Permissions and administration can be a problem and there are plenty issues to work out, but let’s start slowly.

3 Likes

that’s a good idea!

So you mean something like a local server?

If yes, you could take a look at solid-rest by @jeffz. The goal of this package is to wrap a custom storage so that it behaves according to the solid api-spec. I think it supports everything from it, except for Sparql and OPTIONs requests. And some things like permission handling via Acl file are not included (they aren’t part of the api-spec).

You can give solid-rest a custom backend, but it already has a localStorage (which falls back to in-memory storage using objects if not available) and fileStorage (using fs). It is used in solid-auth-cli and there are plans to include it in solid-auth-client too if I remember correctly.

Here’s a short usage example

const SolidRest = require('solid-rest/src/rest');
const RestLocalStorage = require('solid-rest/src/localStorage')
const myLocalStorage = new RestLocalStorage()
// Defaults to ls which makes it usable as app://ls/some/path/
myLocalStorage.prefix = 'ls'
const localRest = new SolidRest([ myLocalStorage ])

// Now you can fallback to using rest
localRest.fetch('app://ls/') // The root folder app://ls/ already exists
    .then(async res => {
        console.log(res.status) // 200
        console.log(res.headers.get('Content-Type')) // text/turtle
        console.log(await res.text()) // "@prefix ldp: <http://www.w3.org/ns/ldp#>.\n<> a ldp:BasicContainer, ldp:Container.\n"
    })
    .catch(console.error)

I’ve also played with the thought to create a browser extension which gives the user the ability to create a local pod and proxies “https://solid.pod.local/” to be handled by solid-rest, but I didn’t find a way to do this kind of proxy with web extensions until now. Here’s the thread: Create local in-browser pod

And I think it would also be possible to create a Dropbox/OneDrive/etc. storage which is used by solid-rest. I think this could also be useful, as many people already have such a cloud storage. So they don’t need to adapt much. The drawback is that some things like Access Control, WebSockets, … won’t work with this. But for some projects this should be enough.

I tried running it using termux. It was fun and worked fine from the local host. (you need to obtain the ssl certificates though - self signed one will do).

I’ve just tested @jeffz solid-rest on Android 9, with termux . all tests seems ok :+1:

4 Likes

I investigated NodeJS on Android in 2017, and it was basically a PITA. I think @jeffz solid-rest is the better path to travel.

(Though since my investigation there is NodeJS for Android Apps, which may give you a better experience. See 2nd answer to link above. In general imo Node is not for mobile, and solutions using it like that feel clumsy and hacky)

I’m currently busy with trying to run a Node Solid Server on mobile and I agree that it feels quite hacky. However I would like to see if the possibility is there. I use Cordova because I found this plugin which lets you run nodejs on mobile using Cordova. It took a while to configure everything but nodejs is working and it can succesfully use packages. However after adding the Node Solid Server repo it started giving new errors.

One of them is the following:

At the first part you see the setup phase and then one package fs-extra which offers extra file system methods causes a permission error. I tried to add a new configPath in createServer or even the root path but they’ll give different errors. I did it like so:

I’ve been stuck with this error for almost a week now and I don’t know where to look further into, or if it just isn’t possible. I looked at solid-rest because that was mentioned here, but I couldn’t find examples of using that in combination with node-solid-server or phone paths.

Does anyone have an idea of how this could happen and could be tackled?

What error are you getting when changing the configPath to a location where you have access rights?

1 Like

Node solid server is very dependent on file system access through libraries like fs-extra and I can’t think of any easy path to getting it working without them. To get Solid-Rest to work, you would need to write a plugin similar to @solid-rest/file/src/index.ts which supplies a few methods to access files on the device. I’m glad to help if you want to go down that path. It would provide use of the databrowser on the device and also syncing between device and a pod.

Have you spoken with @Smag0? His PoPock may be relevant to your project.

1 Like

If I change it to cordova.app.datadir() which returns a writable path used for persistent data storage in the application (see link):

image

I get this error:

But now I actually see that this error happens at a later stage in the server-config. Which you can see here.

It is also strange that the .acl exist but the error says otherwise. When I comment the last part (from 148 to 151, which probably is the wrong this to do), and run, I get these warnings:

E/NODEJS-MOBILE: (node:23100) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, mkdir ''

E/NODEJS-MOBILE: (node:23100) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

(node:23100) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The app doesn’t crash, but when going to localhost on my phone I get this:

So that doesn’t seem to work either, it does load something at least which is hopeful. Sorry for the whole load of information.

Did you double check that this file with the long path /data/data/io.codova.hellocordova/..../.acl actually exists? What does ls -lah or stat say about it?

PoPock might be useful for testing a pod but in this stage it might not be useful because I want to experiment with having the pod running on your phone and this seems more like a Pod manager. (also haven’t spoken to @Smag0 about it.

For now I will try to familiarize myself more with the problem and think about going into this direction. I’ll let you know if I will try to write something like the @solid-rest script! Thanks.