Hello everyone, I'm encountering an issue with my Express server snap where HTTPS requests are failing when accessing the /express-server endpoint using the URL https://192.168.0.205/express-server. However, accessing https://192.168.0.205:9595/express-server works fine (see screenshots below). It's important to note that I'm not using Unix sockets and I am using a reverse proxy to port 9595 (defined in the package assets file). Additional Info: Build environment: Ubuntu 22.04 Snap base: core22 CtrlX CORE X3 (with core 22 app installed) CtrlX Works version: 1.20.5 I'm using self-signed certificates to grant HTTPS access. Additionally, when I hosted the server as HTTP, certain view elements load, but others do not due to HTTP/HTTPS conflict. I've also observed that accessing https://192.168.0.205/express-server throws a 502 Bad Gateway error. And a message that ''The app is currently not available'' is being rendered . At the end, my aim is to maintain HTTPS for all requests, ensuring a secure connection throughout. Screenshots: package.assets File: {
"$schema": "https://json-schema.boschrexroth.com/ctrlx-automation/ctrlx-core/apps/package-manifest/package-manifest.v1.1.schema.json",
"version": "1.0.1",
"id": "datalayer-visualizer-app",
"configuration": {
"appDirectories": [
{
"name": "datalayer-visualizer-app",
"description": "Datalayer Visualizer App",
"icon": "bosch-ic-directory",
"scopes": [],
"copyOnLoad": true,
"writeProtected" : false
}
]
},
"services": {
"proxyMapping": [
{
"name": "express-server.web",
"url": "/express-server",
"binding": ":9595",
"options": [
{
"option": "websocket",
"value": ""
}
]
}
]
},
"menus": {
"overview": [],
"sidebar": [
{
"id": "datalayer-visualizer-app-sidebar",
"title": "Datalayer Visualizer App",
"icon": "bosch-ic-directory",
"link": "/express-server",
"items": []
}
],
"settings": []
}
} app.ts File: #!/usr/bin/env node
// Import required Node.js modules
import fs from 'fs'; // File system module for handling files
import https from 'https'; // HTTPS module for creating secure servers
import express from 'express'; // Web framework for Node.js
import cors from 'cors'; // Middleware for enabling CORS
import dotenv from 'dotenv'; // Load environment variables from .env file
import path from 'path'; // Path module for handling file paths
import cookieParser from 'cookie-parser'; // Middleware for parsing cookies
// Load environment variables from .env file
dotenv.config();
// Security: We have to trust self-signed certificates by default (ctrlX WebServer)
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
// Create a new express application instance
const app = express();
// Enable CORS
app.use(cors({
origin: '*',
methods: ['GET', 'POST', 'PUT', 'DELETE'],
allowedHeaders: '*',
}));
// Serve static files from the public folder
app.use(express.static(path.join(__dirname, 'public')));
// Set the views directory
app.set('views', path.join(__dirname, 'views'));
// Set the view engine to EJS
app.set('view engine', 'ejs');
// Parse incoming requests with JSON payloads
app.use(express.json());
// Parse incoming requests with urlencoded payloads
app.use(express.urlencoded({ extended: false }));
// Parse incoming requests with cookies
app.use(cookieParser());
// Define a route for the root URL ('/')
app.get('/', async (req, res) => {
// Redirect to '/express-server'
res.redirect('/express-server');
});
// Define a route for the main page ('/express-server')
app.get('/express-server', async (req, res) => {
// Render the main page using the EJS template
res.render('index');
});
// Asynchronous function to start the server
async function startServer() {
try {
const options = {
key: fs.readFileSync(path.join(__dirname, 'config','key.pem')),
cert: fs.readFileSync(path.join(__dirname, 'config','cert.pem'))
};
// Port to listen on (default: 9595)
const port = process.env.PORT || 9595;
https.createServer(options, app).listen(port, () => {
console.log(`[Server] Server is running on https://localhost:${port}`);
});
} catch (error) {
console.error('Failed to start server:', error);
}
}
startServer(); Any insights or suggestions on how to troubleshoot and resolve this issue would be greatly appreciated. Thank you! Solution: Issue was resolved by switching the protocol from HTTPS to HTTP, mofifying the static file paths and creating a directory called express-server.
... View more