Add config file and text editor + update server

This commit is contained in:
2025-02-08 14:02:16 -05:00
parent 44461ceef8
commit 68dce7ee2a
14 changed files with 722 additions and 166 deletions

27
server/api/config.js Normal file
View File

@@ -0,0 +1,27 @@
const express = require('express')
const fs = require('fs/promises')
const path = require('path')
const yaml = require('js-yaml')
const router = express.Router()
router.post('/api/config', async (req, res) => {
try {
// Get the raw YAML content from the request body
const yamlContent = req.body
// Validate the YAML by trying to parse it
yaml.load(yamlContent)
// Write to the config file
const configPath = path.join(process.cwd(), 'public', 'config.yaml')
await fs.writeFile(configPath, yamlContent, 'utf8')
res.status(200).json({ message: 'Configuration updated successfully' })
} catch (error) {
console.error('Error updating configuration:', error)
res.status(500).json({ error: 'Failed to update configuration' })
}
})
module.exports = router