cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

Run web based app in virtual ctrlx core

Run web based app in virtual ctrlx core

jawad
Long-established Member

How I can run the web based app in ctrlx Works?

I have a web based app written in nodejs and I built the snap application of that project. Then I have successfully installed that snap app in Virtual Ctrlx Core. 
The project has different routes and APIs in it, how I can run that installed project? 

jawad_0-1700025575184.png

 

10 REPLIES 10

nickH
Community Moderator
Community Moderator

Hi, 

please have a look into what @Sgilk told you, when you asked the same question already. 

"Snap application in nodejs (express server) not working its api"

jawad
Long-established Member

@nickH I have tested the few things mentioned there. but I couldnot find exact solution. 
My question is simple , how I can run snap application (simple web app written in nodejs) in virtual ctrlx core after installation??????

nickH
Community Moderator
Community Moderator

You should build your snap, so it runs automatically after installation (daemon: simple). All our samples in our SDK are build like this. I would really recommend you to look into the SDK for ctrlX AUTOMATION on GitHub.

To get your application running I would recommend you to do the same things my colleague already proposed: 

  1. You should try to run this application outside of the snap context to debug any code issues
  2. Install the snap in your build environment to debug locally in snap context
  3. Install the snap in your ctrlX Virtual CORE and debug via ssh logs

 

Further hint: if you want integrate into the sidebar of the webinterface or if you want to bind behind our reverseproxy see this: Package Assets.

jawad
Long-established Member

look it is running already,
in log book this issue occurs 

jawad_0-1700038847040.png

this issue occurs when I have snap of following code,

#!/usr/bin/env node

const express = require('express');
const app = express();
const port = 3000;

app.get('/', (req, res) => {
  res.send('Hello, Express by exd!22');
});

app.listen(port, () => {
  console.log(`Server is listening on port ${port}`);
});

app.get('/items', (req, res) => {
    const items = ['Item 1', 'Item 2', 'Item 3'];
    res.json(items);
});


function helloWorld() {
    setInterval(() => console.log('Hello World from Exd2', new Date().toUTCString()), 1000)
};

helloWorld();
 
But before it, without express and APIs snap was runing properly and showing console.log in logbook
#!/usr/bin/env node

const express = require('express');
const app = express();
const port = 3000;

function helloWorld() {
    setInterval(() => console.log('Hello World from Exd2', new Date().toUTCString()), 1000)
};

helloWorld();


but now let me ask you a question what is this above error about ? and secondly How I can access following routes? like 
app.get('/items', (req, res) => {
    const items = ['Item 1', 'Item 2', 'Item 3'];
    res.json(items);
});

if i have 1000 routes written in my code, it will start automatically all routes??? as you said earlier ? 

 

nickH
Community Moderator
Community Moderator

Can you check in your snapcraft.yaml if your snap is connected to the -network plug? 
Here a screenshot from a snapcraft.yaml in our SDK (samples-go/hello.webserver):

snap/snapcraft.yaml of go-sample hello.webserversnap/snapcraft.yaml of go-sample hello.webserver

 

  

jawad
Long-established Member

here is my snapcraft.yaml @nickH 

jawad_0-1700041796600.png

 

nickH
Community Moderator
Community Moderator

You may also need "network-bind", I would recommend you to try it out. 

Did you try the other steps I told you? If yes, what were the results? 

  1. You should try to run this application outside of the snap context to debug any code issues
  2. Install the snap in your build environment to debug locally in snap context
  3. Install the snap in your ctrlX Virtual CORE and debug via ssh logs

jawad
Long-established Member

ok. I added that network-bind.

Can you please help me above three points mentioned, how I can try them? @nickH

 

nickH
Community Moderator
Community Moderator
  1. How you can run your own application you should know best. Probably starting your .js script. 
  2. Install the snap in your App Build Environment (which is a ubuntu server machine). Just type in "sudo snap install <your.snap.name> --dangerous". And see if it runs here
  3. Install it on the ctrlX COREvirtual (what you already did). Connect via ssh to the control (you have to activate the ssh-connection in the web-interface of the ctrlX CORE at stettings->ssh). 
    Try these commands for example:

jawad
Long-established Member

Thank you @nickH 
I have achevied this by runing the ip address with port no. and route which is defined in code. it works . 

jawad_0-1700052565193.png

 

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist