Reporting back. Using existing libraries, this is much simpler than I was making it. Here's some sample Python code which posts "Hello, World!" to topic ID 2. Thanks, @julian, for telling me about socket.io.
from socketIO_client import SocketIO, LoggingNamespace import requests import json session = requests.Session() csrf_token = json.loads(session.get('http://yourdomain:port/api/config').text)['csrf_token'] headers = { 'x-csrf-token': csrf_token } data = { "username": "yourUsername", "password": "yourPassword" } response = session.post("http://yourdomain:port/login", headers=headers, data=data) def on_response(*args): print('on_response', json.dumps(args)) with SocketIO('yourdomain', port, LoggingNamespace, cookies=session.cookies.get_dict()) as s: s.emit('posts.reply', {'tid': 2, 'content': "Hello, World!"}, on_response) s.wait_for_callbacks(seconds=1)[QUESTION] Plugin ACP templates relative URLs
-
I think every plugin I looked at so far uses inline
js/css
on the ACP template, I want to be able to include a js and css files instead.Say I have this plugin
nodebb-plugin-something index.js plugin.json package.json public js acp.something.js // <-- I want this to be accessible only on in the ACP page of the plugin, no need to compile it into nodebb.min.js, I don't want to use "filter:scripts.get" css acp.something.css // <-- same as acp.something.js templates admin plugins something.tpl
in
something.tpl
<link href="{RELATIVE_PATH}css/acp.something.css" rel="stylesheet" > <script src="{RELATIVE_PATH}js/acp.something.js"></script>
this only works if
RELATIVE_PATH === ""
, but what about folder installs ?<script src="/plugins/nodebb-plugin-something/js/acp.something.js"></script>
somewhere in
index.js
res.render('admin/plugins/something', {RELATIVE_PATH: nconf.get('relative_path') /* do i have to do this, or is this var global to the templates somehow? */, csrf: req.csrfToken()});
^ question in comment
-
Because you control where the admin page is mounted:
myPlugin.init = function(data, callback) { data.router.get('/admin/plugins/myPlugin', data.middleware.admin.buildHeader, render); data.router.get('/api/admin/plugins/myPlugin', render); callback(); }
... you can expect that
../../
gets you back to the public root, so no need to pass inRELATIVE_PATH
.Also, no need to pass in
csrf
either -
got it thanks!