Hello there, after deploying initial node project (based on module starter) on CapRover instance, project is deployed but not running, and there are errors in CapRover console:
2024-03-08T08:36:21.988862912Z npm ERR! Missing script: "start"
2024-03-08T08:36:21.991010996Z npm ERR!
2024-03-08T08:36:21.991044777Z npm ERR! Did you mean one of these?
2024-03-08T08:36:21.991049091Z npm ERR! npm star # Mark your favorite packages
2024-03-08T08:36:21.991052533Z npm ERR! npm stars # View packages marked as favorites
2024-03-08T08:36:21.991055797Z npm ERR!
2024-03-08T08:36:21.991058890Z npm ERR! To see a list of scripts, run:
2024-03-08T08:36:21.991062157Z npm ERR! npm run
2024-03-08T08:36:21.997225287Z
2024-03-08T08:36:21.997244260Z npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-03-08T08_36_21_633Z-debug-0.log
project adress: https://discourse-telegram-bot.cap.sealcode.org/
Please provide the package.json
and captain-definition
file contents
package.json
{
"name": "module-starter",
"version": "0.0.1",
"description": "module template",
"main": "lib/index.js",
"scripts": {
"test": "mocha",
"build": "tsc",
"prepare": "npm run build",
"clean-coverage": "rm -rf coverage .nyc_output .xunit",
"coverage": "npm run clean-coverage && nyc mocha",
"test-reports": "npm run clean-coverage && nyc --reporter clover mocha --reporter xunit --reporter-option output=.xunit",
"coverage-html": "npm run test-reports && nyc report --reporter lcov && xdg-open coverage/lcov-report/index.html"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@types/express": "^4.17.21",
"@types/mocha": "^10.0.1",
"@types/node": "^20.11.25",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@typescript-eslint/parser": "^5.58.0",
"eslint": "^8.38.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-with-tsc-error": "^0.0.8",
"mocha": "^10.2.0",
"mri": "^1.2.0",
"nyc": "^15.1.0",
"prettier": "^2.8.7",
"source-map-support": "^0.5.21",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
},
"types": "./@types/index.d.ts",
"dependencies": {
"axios": "^1.6.7",
"body-parser": "^1.20.2",
"express": "^4.18.3"
}
}
captain-definition
{
"schemaVersion": 2,
"dockerfileLines": [
"FROM node:20-alpine",
"RUN mkdir -p /usr/src/app",
"WORKDIR /usr/src/app",
"COPY ./ /usr/src/app",
"RUN npm install && npm cache clean --force && npm run build",
"ENV NODE_ENV production",
"ENV PORT 80",
"EXPOSE 80",
"CMD [ \"npm\", \"start\" ]"
]
}
Yep - the start
script is missing from package.json’s scripts
section. Add it and it should be OK. It should say "start": "node lib/index.js"
or similar
i thought about it, but then there is such error
---> Running in 16def38af37d
Removing intermediate container 16def38af37d
---> b37bb307aa8d
Step 7/9 : ENV PORT 80
---> Running in 6cc239563462
Removing intermediate container 6cc239563462
---> 042699fd6c68
Step 8/9 : EXPOSE 80
---> Running in be16f0198347
Removing intermediate container be16f0198347
---> 49f26e2b273e
Step 9/9 : CMD [ "npm", "start" ]
---> Running in 4687bec06187
Removing intermediate container 4687bec06187
---> 4cdef9924746
[Warning] One or more build-args [CAPROVER_GIT_COMMIT_SHA] were not consumed
Successfully built 4cdef9924746
Successfully tagged img-captain-discourse-telegram-bot:latest
Build has finished successfully!
What error do you mean? The output looks clean
yyes im confused, no error but build failed
actually passed, i dont know why it shown fsil before
1 Like
so it looks there is still some problem with this CapRover domain https://discourse-telegram-bot.cap.sealcode.org/
and when i send an exemplary github webhook (created for some of my repos) the response is 502
Request URL: http://discourse-telegram-bot.cap.sealcode.org/
Request method: POST
Accept: */*
Content-Type: application/json
User-Agent: GitHub-Hookshot/6ca68c0
X-GitHub-Delivery: a18073a0-dd56-11ee-9a9d-92bec53c79d8
X-GitHub-Event: ping
X-GitHub-Hook-ID: 465387396
X-GitHub-Hook-Installation-Target-ID: 741203322
X-GitHub-Hook-Installation-Target-Type: repository
X-Hub-Signature: sha1=c309348b9aaa33bf6fa774cefca08fe501b7ff5a
X-Hub-Signature-256: sha256=b421c158a6731538c0d88ad852d9ac9b46ef40d45fc946b96bb15dc6163f022e
On what port is your application listening to HTTP requests?
container is on http 80, my node app on 3000
You need to get those aligned, then. I suspect it’d be easiest to just tell Caprover to use port 3000 in the GUI config:
Can you show the code where you setup the routes for the http server in node?
import express, { Request, Response } from "express";
const bodyParser = require("body-parser");
const axios = require('axios');
const app = express();
const PORT = 3000;
app.use(bodyParser.json())
app.get("/discourse", async (req: Request, res: Response) => {
const options = {
'method': 'GET',
'url': 'http://discourse-telegram-bot.cap.sealcode.org/',
'headers': {
'Content-Type': 'application/json',
'Accept': '*/*',
'Connection': 'close',
'Host': 'XXX',
'User-Agent': 'Discourse/2.4.0.beta4',
'X-Discourse-Instance': 'https://XXX',
'X-Discourse-Event-Id': '11',
'X-Discourse-Event-Type': 'notification',
'X-Discourse-Event': 'notification_created',
'X-Discourse-Event-Signature': 'sha256=XXX'
}
};
try {
const result = await axios(options);
if(result.status === 200){
res.send(result.data)
}
} catch (e) {
console.log(e);
}
});
app.get("/", async (req: Request, res: Response) => {
console.log({req, res});
})
app.listen(PORT, () => console.log(`running on port ${PORT}`))
request headers for discourse are not completed, I dont know the host, instance and signature
Well, it seems that your webhooks are sending a POST method and you only have listeners for GET.
As for the discourse headers - there’s no need to send any requests from the bot repo to discourse now. Discourse will send information to that bot with webhooks and we just need to log them
1 Like
thank you for all the tips, now it works, at least in a way i receive some fragments of discussion and info about topic:
For the broken link, you may have to run `npm install` to get the newest sealgen\n\nI did that for https://hub.sealcode.org/D1378 but it didnt help and still had to skip tests becasue of this error","moderator":false,"admin":false,"staff":false,"user_id":76,"hidden":false,"trust_level":2,"deleted_at":null,"user_deleted":false,"edit_reason":null,"wiki":false,"reviewable_id":null,"reviewable_score_count":0,"reviewable_score_pending_count":0,"topic_posts_count":8,"topic_filtered_posts_count":8,"topic_archetype":"regular","category_slug":"aspazja"}}
2024-03-09T12:24:06.834742795Z {"notification":{"id":32651,"user_id":1,"notification_type":2,"read":false,"high_priority":false,"created_at":"2024-03-09T12:24:06.775Z","post_number":8,"topic_id":1937,"fancy_title":"Unexpected issues with tests in aspazja","slug":"unexpected-issues-with-tests-in-aspazja","data":{"topic_title":"Unexpected issues with tests in aspazja","original_post_id":7400,"original_post_type":1,"original_username":"FilipI","revision_number":null,"display_username":"FilipI"}}}
what about secret key for validation? here is about secret, but as far as i understand I would need to have accound in discourse admin panel to set up webhook headers Webhook Secret issue - #8 by simon - support - Discourse Meta
1 Like
so i will send how it is now, but how tests should looks like? I guess to test this webhook I’d need to do some integration tests
We don’t have to implement validation at this point - we’re just laying the foundation to further develop the main functionality. So we can just ignore the validation header for now and add validation in a later stage.
That’s a good question - so far we don’t have any functionality, so there’s not much to test integration-wise. At a later stage we can test the code by making mock requests to it, and checking the resulting behavior - kind of like we do with testing Sealious itself
1 Like