Fixed a few things.

This commit is contained in:
Tom Butcher 2025-06-02 02:00:32 +01:00
parent f9525da7d7
commit ec0f2e4d16
5 changed files with 57 additions and 60 deletions

4
Jenkinsfile vendored
View File

@ -32,8 +32,8 @@ node {
stage('Deploy to printer1') {
def remote = [:]
remote.name = 'printer1'
remote.host = 'printer1.tombutcher.local'
remote.name = 'farmcontrolserver'
remote.host = 'farmcontrol.tombutcher.local'
remote.user = 'ci'
remote.password = 'ci'
remote.allowAnyHosts = true

View File

@ -1,19 +1,40 @@
{
"server": {
"port": 8081,
"logLevel": "info"
},
"auth": {
"enabled": true,
"keycloak": {
"url": "https://auth.tombutcher.work",
"realm": "master",
"clientId": "farmcontrol-client",
"clientSecret": "GPyh59xctRX83yfKWb83ShK6VEwHIvLF"
"development": {
"server": {
"port": 8081,
"logLevel": "debug"
},
"requiredRoles": []
"auth": {
"enabled": true,
"keycloak": {
"url": "https://auth.tombutcher.work",
"realm": "master",
"clientId": "farmcontrol-client",
"clientSecret": "GPyh59xctRX83yfKWb83ShK6VEwHIvLF"
},
"requiredRoles": []
},
"database": {
"url": "mongodb://localhost:27017/farmcontrol"
}
},
"database": {
"url": "mongodb://192.168.68.53:27017/farmcontrol"
"production": {
"server": {
"port": 8081,
"logLevel": "info"
},
"auth": {
"enabled": true,
"keycloak": {
"url": "https://auth.tombutcher.work",
"realm": "master",
"clientId": "farmcontrol-client",
"clientSecret": "GPyh59xctRX83yfKWb83ShK6VEwHIvLF"
},
"requiredRoles": []
},
"database": {
"url": "mongodb://farmcontrol.tombutcher.local:27017/farmcontrol"
}
}
}

View File

@ -8,57 +8,31 @@ const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const CONFIG_PATH = path.resolve(__dirname, "../config.json");
// Default configuration
const DEFAULT_CONFIG = {
server: {
port: 8080,
cors: {
origin: "*",
methods: ["GET", "POST"],
},
},
auth: {
enabled: true,
keycloak: {
url: "https://auth.tombutcher.work",
realm: "master",
clientId: "farmcontrol-client",
clientSecret: "MBtsENnnYRdJJrc1tLBJZrhnSQqNXqGk",
},
requiredRoles: ["printer-user"],
},
database: {
url: "mongodb://localhost:27017/farmcontrol",
},
};
// Determine environment
const NODE_ENV = process.env.NODE_ENV || 'development';
// Load or create config file
// Load config file
export function loadConfig() {
try {
if (fs.existsSync(CONFIG_PATH)) {
const configData = fs.readFileSync(CONFIG_PATH, "utf8");
return JSON.parse(configData);
} else {
fs.writeFileSync(
CONFIG_PATH,
JSON.stringify(DEFAULT_CONFIG, null, 2),
);
console.log(`Created default configuration at ${CONFIG_PATH}`);
return DEFAULT_CONFIG;
if (!fs.existsSync(CONFIG_PATH)) {
throw new Error(`Configuration file not found at ${CONFIG_PATH}`);
}
const configData = fs.readFileSync(CONFIG_PATH, "utf8");
const config = JSON.parse(configData);
if (!config[NODE_ENV]) {
throw new Error(`Configuration for environment '${NODE_ENV}' not found in config.json`);
}
return config[NODE_ENV];
} catch (err) {
console.error("Error loading config:", err);
return DEFAULT_CONFIG;
throw err;
}
}
// Save configuration
export function saveConfig(config) {
try {
fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2));
return true;
} catch (err) {
console.error("Error saving config:", err);
return false;
}
// Get current environment
export function getEnvironment() {
return NODE_ENV;
}

View File

@ -5,6 +5,7 @@ const stockEventSchema = new Schema(
{
type: { type: String, required: true },
value: { type: Number, required: true },
unit: { type: String, required: true},
subJob: { type: Schema.Types.ObjectId, ref: "PrintSubJob", required: false },
job: { type: Schema.Types.ObjectId, ref: "PrintJob", required: false },
filamentStock: { type: Schema.Types.ObjectId, ref: "FilamentStock", required: true },

View File

@ -813,6 +813,7 @@ export class PrinterDatabase {
subJob: subJobId,
job: jobId,
filamentStock: filamentStockId,
unit: 'g',
updatedAt: new Date(),
createdAt: new Date()
});