https://github.com/octoprint/findmyoctoprint-server
https://github.com/octoprint/findmyoctoprint-server
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/octoprint/findmyoctoprint-server
- Owner: OctoPrint
- Created: 2021-05-04T12:46:31.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-05-04T16:54:38.000Z (over 4 years ago)
- Last Synced: 2024-12-29T02:00:31.867Z (about 1 year ago)
- Language: Python
- Size: 49.8 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FindMyOctoPrint-Server
## Installation
```
git clone https://github.com/OctoPrint/FindMyOctoPrint-Server
cd FindMyOctoPrint-Server
docker build -t findmyoctoprint .
docker run findmyoctoprint
```
There's also a sample `docker-compose.yml` for you to adjust as needed.
## Usage
```
$ docker run findmyoctoprint --help
Usage: __init__.py [OPTIONS]
Options:
--address TEXT The host under which to run
--port INTEGER The port under which to run
--cors TEXT Setting for Allowed-Origin-Host CORS header
--help Show this message and exit.
```
### Example
```
$ docker run findmyoctoprint --port 5000 --address 127.0.0.1 --cors "http://example.com"
2016-09-26 17:22:21,555 - findmyoctoprint.server - INFO - Starting Find My OctoPrint server...
2016-09-26 17:22:21,628 - findmyoctoprint.server - INFO - Binding to 127.0.0.1:5000
```
## Setup Nginx
Configuration samples can be found in ``extra/nginx``.
When accessing the registry via https from a http page (e.g.
you are accessing the page on ``http://example.com`` and it uses
``https://example.com/registry`` as endpoint for querying the registry),
make sure to set the CORS allowed header via the ``--cors`` command
line argument on server start to allow access to the registry from
``http://example.com``:
```
$ docker run findmyoctoprint --port 5000 --address 127.0.0.1 --cors "http://example.com"
```
## Sample page & client usage
The following sample page is very similar to the included stock ``index.html`` but
shows how to configure the included ``findmyoctoprint.js`` module.
The server here is assumed as running under both ``http://example.com``
and ``https://example.com`` - adjust accordingly.
The endpoint for querying the server's registry is set via ``findmyoctoprint.options.queryUrl``.
``findmyoctoprint.discover`` returns a promise - individual discovered
entries are provided as progress, the promise is finally resolved with a full
set of all discovered entries, as an object mapping from found UUID to discovered entry.
Entries consist of the fields ``url``, ``name`` and ``uuid``.
```
Find my OctoPrint
$(function() {
findmyoctoprint.options.queryUrl = "https://example.com/registry";
var performDiscovery = function() {
var discovered = $("#discovered");
discovered.empty();
findmyoctoprint.discover()
.progress(function(entry) {
console.log("Found entry:", entry);
discovered.append($("<li><a href=\"" + entry.url + "\" target=\"_blank\" title=\"" + entry.uuid + "\">" + entry.name + "</a></li>"));
})
.done(function(entries) {
console.log("Discovery done, entries:", entries);
})
.fail(function() {
console.log("Discovery failed");
});
};
$("#rescan").click(performDiscovery);
performDiscovery();
});
Find my OctoPrint
```