diff --git a/Jenkinsfile b/Jenkinsfile index 36205aa..4652068 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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 diff --git a/config.json b/config.json index 4e2f1e0..4f56fd1 100644 --- a/config.json +++ b/config.json @@ -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" + } } } diff --git a/src/config.js b/src/config.js index 8350bb8..b11279b 100644 --- a/src/config.js +++ b/src/config.js @@ -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; } diff --git a/src/database/stockevent.schema.js b/src/database/stockevent.schema.js index 25f5634..92c5d65 100644 --- a/src/database/stockevent.schema.js +++ b/src/database/stockevent.schema.js @@ -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 }, diff --git a/src/printer/database.js b/src/printer/database.js index 8e5b819..839c335 100644 --- a/src/printer/database.js +++ b/src/printer/database.js @@ -813,6 +813,7 @@ export class PrinterDatabase { subJob: subJobId, job: jobId, filamentStock: filamentStockId, + unit: 'g', updatedAt: new Date(), createdAt: new Date() });