Fixed a few things.
This commit is contained in:
parent
f9525da7d7
commit
ec0f2e4d16
4
Jenkinsfile
vendored
4
Jenkinsfile
vendored
@ -32,8 +32,8 @@ node {
|
|||||||
|
|
||||||
stage('Deploy to printer1') {
|
stage('Deploy to printer1') {
|
||||||
def remote = [:]
|
def remote = [:]
|
||||||
remote.name = 'printer1'
|
remote.name = 'farmcontrolserver'
|
||||||
remote.host = 'printer1.tombutcher.local'
|
remote.host = 'farmcontrol.tombutcher.local'
|
||||||
remote.user = 'ci'
|
remote.user = 'ci'
|
||||||
remote.password = 'ci'
|
remote.password = 'ci'
|
||||||
remote.allowAnyHosts = true
|
remote.allowAnyHosts = true
|
||||||
|
|||||||
23
config.json
23
config.json
@ -1,4 +1,24 @@
|
|||||||
{
|
{
|
||||||
|
"development": {
|
||||||
|
"server": {
|
||||||
|
"port": 8081,
|
||||||
|
"logLevel": "debug"
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"enabled": true,
|
||||||
|
"keycloak": {
|
||||||
|
"url": "https://auth.tombutcher.work",
|
||||||
|
"realm": "master",
|
||||||
|
"clientId": "farmcontrol-client",
|
||||||
|
"clientSecret": "GPyh59xctRX83yfKWb83ShK6VEwHIvLF"
|
||||||
|
},
|
||||||
|
"requiredRoles": []
|
||||||
|
},
|
||||||
|
"database": {
|
||||||
|
"url": "mongodb://localhost:27017/farmcontrol"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"production": {
|
||||||
"server": {
|
"server": {
|
||||||
"port": 8081,
|
"port": 8081,
|
||||||
"logLevel": "info"
|
"logLevel": "info"
|
||||||
@ -14,6 +34,7 @@
|
|||||||
"requiredRoles": []
|
"requiredRoles": []
|
||||||
},
|
},
|
||||||
"database": {
|
"database": {
|
||||||
"url": "mongodb://192.168.68.53:27017/farmcontrol"
|
"url": "mongodb://farmcontrol.tombutcher.local:27017/farmcontrol"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,57 +8,31 @@ const __filename = fileURLToPath(import.meta.url);
|
|||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
const CONFIG_PATH = path.resolve(__dirname, "../config.json");
|
const CONFIG_PATH = path.resolve(__dirname, "../config.json");
|
||||||
|
|
||||||
// Default configuration
|
// Determine environment
|
||||||
const DEFAULT_CONFIG = {
|
const NODE_ENV = process.env.NODE_ENV || 'development';
|
||||||
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",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Load or create config file
|
// Load config file
|
||||||
export function loadConfig() {
|
export function loadConfig() {
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync(CONFIG_PATH)) {
|
if (!fs.existsSync(CONFIG_PATH)) {
|
||||||
const configData = fs.readFileSync(CONFIG_PATH, "utf8");
|
throw new Error(`Configuration file not found at ${CONFIG_PATH}`);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
} catch (err) {
|
||||||
console.error("Error loading config:", err);
|
console.error("Error loading config:", err);
|
||||||
return DEFAULT_CONFIG;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save configuration
|
// Get current environment
|
||||||
export function saveConfig(config) {
|
export function getEnvironment() {
|
||||||
try {
|
return NODE_ENV;
|
||||||
fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
||||||
return true;
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Error saving config:", err);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ const stockEventSchema = new Schema(
|
|||||||
{
|
{
|
||||||
type: { type: String, required: true },
|
type: { type: String, required: true },
|
||||||
value: { type: Number, required: true },
|
value: { type: Number, required: true },
|
||||||
|
unit: { type: String, required: true},
|
||||||
subJob: { type: Schema.Types.ObjectId, ref: "PrintSubJob", required: false },
|
subJob: { type: Schema.Types.ObjectId, ref: "PrintSubJob", required: false },
|
||||||
job: { type: Schema.Types.ObjectId, ref: "PrintJob", required: false },
|
job: { type: Schema.Types.ObjectId, ref: "PrintJob", required: false },
|
||||||
filamentStock: { type: Schema.Types.ObjectId, ref: "FilamentStock", required: true },
|
filamentStock: { type: Schema.Types.ObjectId, ref: "FilamentStock", required: true },
|
||||||
|
|||||||
@ -813,6 +813,7 @@ export class PrinterDatabase {
|
|||||||
subJob: subJobId,
|
subJob: subJobId,
|
||||||
job: jobId,
|
job: jobId,
|
||||||
filamentStock: filamentStockId,
|
filamentStock: filamentStockId,
|
||||||
|
unit: 'g',
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
createdAt: new Date()
|
createdAt: new Date()
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user