@baris Alright. Clear. Thanks a lot!

nullpointer
Posts
-
-
@baris where exactly should I implement my custom logic? Is it after firing the hook and filtering the hook result, or somewhere else?
-
I am using the hook
filter:category.topics.prepare
to get alltids
under certain category. I need to filter thistids
based on certain condition, because I don't want to load the whole topics under the category. What is the best approach to do this?This is piece of code that I currently use (copied from
src/categories/topics.js
) :let results = await plugins.hooks.fire('filter:category.topics.prepare', data); const tids = await Categories.getTopicIds(results); let topicsData = await topics.getTopicsByTids(tids, data.uid);
Thanks in advance.
-
@baris said in Making a topic content NOT mandatory:
Try with this change https://github.com/NodeBB/NodeBB/commit/8c762d3228ee622984a6eb4bad5cbec810c27e60 and let me know.
It works!
Thanks a lot @baris -
Can I make the
content
of a main post becomes NOT mandatory when creating a topic?
Currently I create a topic by using API with this json body:{ "cid": 5, "title": "Topic title", "content": "Topic content for main post", "tags": [ "Development" ] }
I want to remove the
content
field so the json body becomes like this:{ "cid": 5, "title": "Topic title", "tags": [ "Development" ]
I know I can set the post length to 0 in ACP, but I got this response when creating topic without the
content
field{ "status": { "code": "bad-request", "message": "Please enter a longer post. Posts should contain at least 0 character(s)." }, "response": {} }
Basically I want to make the
content
field optional. Any suggestion?Thanks in advance.
-
@baris said in How do I disable file logging?:
The configuration of the logger is here https://github.com/NodeBB/NodeBB/blob/master/src/prestart.js#L12-L45
Thank you!
-
Hello, is there any way I can disable file logging? I only need the console output logging. I can see this code for web install logging:
winston.configure({ level: 'verbose', format: winston.format.combine.apply(null, formats), transports: [ new winston.transports.Console({ handleExceptions: true, }), new winston.transports.File({ filename: 'logs/webinstall.log', handleExceptions: true, }), ], });
But not for global logging system. Thanks in advance.
-
I recently deployed my NodeBB in a docker container, and install the plugin locally by copying my plugin into node_modules directory.
When I started the NodeBB server, I got this message:2023-01-24T08:59:05.922Z [4567/181] - warn: [plugins] "nodebb-plugin-my-plugin" is active but not installed.
This is my Dockerfile content:
FROM node:16.14.0 RUN mkdir -p /usr/src/app && chown -R node:node /usr/src/app WORKDIR /usr/src/app RUN apt-get install git ARG NODE_ENV ENV NODE_ENV $NODE_ENV COPY --chown=node:node install/package.json /usr/src/app/package.json USER node COPY --chown=node:node . /usr/src/app RUN npm install --only=prod && npm cache clean --force RUN git clone https://bitbucket.org/dev/nodebb-plugin-my-plugin.git RUN cp -r nodebb-plugin-my-plugin node_modules/ ENV NODE_ENV=production \ daemon=false \ silent=false EXPOSE 4567 USER root RUN chown root:root ./ -R CMD node ./nodebb activate nodebb-plugin-my-plugin; node ./nodebb build; node ./nodebb start -l
The plugin was successfully installed when I run it without docker container.
Please give me some suggestions. Thanks in advance. -
@baris how can I miss this piece of code
Thanks for pointing me out! Solved!
Happy new years
-
How can I get all of the users who upvote/downvote a post? How can I add those voters data (
usernames
orpids
) to the json response of this API endpointhttps://localhost:4567/api/category/1
?Please help. Thank you.
-
Update:
I saw this code in NodeBB unit test:
helpers.connectSocketIO = function (res, callback) { const io = require('socket.io-client'); let cookies = res.headers['set-cookie']; cookies = cookies.filter(c => /express.sid=[^;]+;/.test(c)); const cookie = cookies[0]; const socket = io(nconf.get('base_url'), { path: `${nconf.get('relative_path')}/socket.io`, extraHeaders: { Origin: nconf.get('url'), Cookie: cookie, }, }); socket.on('connect', () => { callback(null, socket); }); socket.on('error', (err) => { callback(err); }); };
I have followed this code but still get the same result.
-
@oplik0 thanks for your detail explanation.
I have tried to change my configuration as you suggest. Here is my config:
Here is my client code:
var socket = io('https://dev-forum.domain.io', { transport: ["polling", "websocket"], path: "/socket.io/", extraHeaders: { withCredentials: true, cookie: 'express.sid=s%3Am0UuuyatTTSajjAnI5gGSukaJSHJaiKpIVhb3H7L.TW4c4vZn4blOnWV1gilF9HhMqFc9g9V7NnLLZHMAmFg; Domain=dev-forum.domain.io; Path=/; HttpOnly; SameSite=Lax', }, });
Now I got this error on my console:
Refused to set unsafe header "cookie" Access to XMLHttpRequest at 'https://dev-forum.domain.io/socket.io/?EIO=4&transport=polling&t=OKjgnov' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field withcredentials is not allowed by Access-Control-Allow-Headers in preflight response.
-
@baris I have tried to create some users and performing ban/unban the users. Still no event received.
-
Update:
I can receive an event
event:user_status_change
on my browser console by using this additional code to catch all events:var listener = (eventName, ...args) => { console.log(eventName, args); } socket.onAny(listener);
But still, I can not receive
event:new_post
andevent:new_topic
. Did I miss something? -
@PitaJ I tried to make a new post and a new topic. But there is no event received by the socket event handler. Is there any documentation regarding this issue?
-
Hello, I am trying to get a realtime update for my custom frontend. I tried to connect to the socket endpoint using this plain jquery code:
var socket = io('http://localhost:4567', { transport: ["polling", "websocket"], path: "/socket.io/", }); socket.on('connect', () => { console.log("Connected ..."); }); socket.on('event:new_post', function (data) { console.log(data); }); socket.on('event:new_topic', function (data) { console.log(data); });
I can get the connect response on the browser console, but when I create a new topic, I can not get the update. Am I doing something wrong?
Please give me some advice. Thank you
-
@baris thank you! I'll try your solution and update here
-
Hello, I am creating a custom frontend using nodebb API. I want to get all the topics inside a category, along with the main post of that topic. Currently I can get all the topics inside a category using this endpoint:
http://localhost:4567/api/category/1
And I got this json response:
... ... "topics": [ { "cid": 1, "lastposttime": 1670832226781, "mainPid": 7, "postcount": 4, "slug": "5/bbca-mencapai-ath-di-harga-9000", "tid": 5, "timestamp": 1670829972612, "title": "$BBCA mencapai ATH di harga 9000", "uid": 3, "viewcount": 11, "postercount": 3, "teaserPid": 11, ... ...
This response only give me the mainPid that forces me to make another API call to get the post detail content. How can I modify this response, so I can get the whole content of the main post (not only the mainPid)? or at least the complete post content?
Please give me some advice. Thank you.
RE: Modifying Hooks Behavior (filter:category.topics.prepare)
RE: Modifying Hooks Behavior (filter:category.topics.prepare)
Modifying Hooks Behavior (filter:category.topics.prepare)
RE: Making a topic content NOT mandatory
Making a topic content NOT mandatory
RE: How do I disable file logging?
How do I disable file logging?
NodeBB plugin is active but not installed
RE: Getting all user who upvote/downvote a post
Getting all user who upvote/downvote a post
RE: Connecting to socket endpoint from a custom frontend
RE: Connecting to socket endpoint from a custom frontend
RE: Connecting to socket endpoint from a custom frontend
RE: Connecting to socket endpoint from a custom frontend
RE: Connecting to socket endpoint from a custom frontend
Connecting to socket endpoint from a custom frontend
RE: How to add main post content of topic to topic lists?
How to add main post content of topic to topic lists?