Add config file and text editor + update server
This commit is contained in:
27
server/api/config.js
Normal file
27
server/api/config.js
Normal 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
|
||||
Reference in New Issue
Block a user