RdeLange / nomie-plugin-api

API plugin for Nomie6-oss edition
7 stars 2 forks source link

How to selfhost plugin? #1

Open alexkutsan opened 1 year ago

alexkutsan commented 1 year ago

I was trying to set up plugin using https://dailynomie.github.io/nomie-plugin-api/ Then I setup the API server on the same domain and my nomie with but with prefix /ui : https://github.com/RdeLange/nomie-server-api

But when I am trying to setup the API server - I catch CORS issue in the browser as soon as the plugin origin: dailynomie.github.io does not match the domain of my server.

изображение

Soluiton would be to store the plugin itself on my domain, but how can I do it?

RdeLange commented 1 year ago

I need to have some more info to validate where the problem lies, so I have some questions:

Then I am wondering how you installed the api server:

alexkutsan commented 1 year ago

you installed the plugin via https://dailynomie.github.io/nomie-plugin-api/ => correct? Yes I use docker compose for nomie, CouchDB and API nomie API:

version: '3.1'
services:
  nomie6:
    image: ghcr.io/qcasey/nomie6-oss:master
    restart: unless-stopped
    ports:
      - ${INTERNAL_IP}:18572:80

  nomieapiserver:
    image: rdelange/dailynomie-apiserver:latest
    container_name: dailynomie-apiserver-docker
    volumes:
    - ./nomieapiserver_data:/home
    ports:
        - "${INTERNAL_IP}:1440:1880"

  couchdb:
    image: couchdb:3
    restart: unless-stopped
    ports:
      - ${INTERNAL_IP}:5984:5984
    environment:
      - NODENAME=couchdb
      - COUCHDB_USER=${COUCH_DB_USER}
      - COUCHDB_PASSWORD=${COUCH_DB_PASSWORD}
    volumes:
      - ./data:/opt/couchdb/data
      - ./couchdb.ini:/opt/couchdb/etc/local.d/docker.ini

Then I have nginx configuration to access my nomie, CouchDB, and nomie API server:

server {
  set $forward_scheme http;
  set $server         "INTERNAL_IP";
  set $port           1440;
  server_name wellness.alexkutsan.me;
  location /nomie_db {
    proxy_pass       http://100.106.66.60:5984;
  }
  location /ui {
    proxy_pass       http://100.106.66.60:1440;
  }
}

I was trying to setup nomie API server to separate domain, but I receive CORS issue as well, the same CORS issue, when I try to use api.dailynomie.com as nomie API server

изображение

I am pretty sure, that if I host a plugin on my domain - the CORS issue should be gone, but I don't know how can I host plugin.

alexkutsan commented 1 year ago

I was trying to create dockerfile for this repo:

FROM node:14-alpine
WORKDIR /app
COPY . /app
RUN npm install
EXPOSE 5000
ENV NODE_ENV=production
CMD ["npm", "start", "--host", "0.0.0.0"]

But it still listening on localhost :


  Your application is ready~! 🚀

  - Local:      http://localhost:5000
  - Network:    Add `--host` to expose

────────────────── LOGS ──────────────────

And I can't reach it by external IP

RdeLange commented 1 year ago

Hi,

I have create an docker image for the plugin: ghcr.io/rdelange/nomie-plugin-api:main

it exposes port 5000.

Can you try using this image, running on your own domain? You can then install the plugin in Nomie by giving the webaddress to the docker container.

I am curious if this will indeed solve the problem.

Regards, Ronald

alexkutsan commented 1 year ago

Added to compose:

  nomie_api_plugin:
    image: ghcr.io/rdelange/nomie-plugin-api:main
    ports:
      - 100.106.66.60:5000:5000

But the plugin is not full loaded : изображение

RdeLange commented 1 year ago

Apologies, I made an error in the image. I have corrected that now. Can you try it again? make sure to delete the old image locally first so it will fetch the new one

alexkutsan commented 1 year ago

Thank you for your efforts! There is still an issue. To avoid the CORS issue - I should use the same hostname as nomie, so I need to host it by other path /nomie-plugin-api But ghcr.io/rdelange/nomie-plugin-api:main host plugin by root math, and I can't host it that way on the same domain as nomie. How to make it available by /nomie-plugin-api subpath?

RdeLange commented 1 year ago

Hi, I am not sure if this is a issue not having Nomie ad the Plugin running on the same domain as technically speaking, Nomie and the Plugin are not communicating in a 'server' - 'client' way, but the are communicating directly, in browser, via an Iframe message bus.

Can you please explain me more precise when the cors issue is happening in the process?

  1. You have Nomie running
  2. You load the plugin in nomie via plugindomain:5000
  3. The plugin gets loaded and you can open the plugin
  4. in the plugin settings you try to fetch the API

I assume that you get the error at step 4? That is the communication between the API server and the Plugin which takes place totally outside the Nomie App (technically)

RdeLange commented 1 year ago

I took the liberty to test with your domain. Something strange is happening as I was able to:

Screenshot 2023-03-20 at 22 48 45

So it is working. From experience I know that sometimes working within your own network, behind your own router can give unexpected results. You might try to see if it is working if you connect to your Nomie server from outside your own network (for example via a 4g connection on your phone)