forked from deadvey/blogger-nodejs
Support for uncached data loading
So you don't have to restart the server, you can add "cache_data": false option to config.json to not cache data. Documented in CONFIG.md I added a require_module function that either does or does not cache the data based on this configuration option. Signed-off-by: deadvey <deadvey@deadvey.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { createRequire } from "module";
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
const func = require('./functions.js')
|
||||
const config = require("../config.json")
|
||||
const fs = require("fs")
|
||||
|
||||
@@ -8,14 +9,14 @@ export function getdata(data, index=-1) {
|
||||
|
||||
if (config["data_storage"] == "json") {
|
||||
if (data == "posts" || data == 'users' || data == 'comments') {
|
||||
let result = require(`../data/${data}.json`)
|
||||
let result = func.require_module(`../data/${data}.json`)
|
||||
if (index != -1) {
|
||||
return result[index]
|
||||
}
|
||||
return result
|
||||
}
|
||||
else if (data == "hitcount") {
|
||||
let result = require('../data/data.json') // This file is actually called data.json
|
||||
let result = func.require_module('../data/data.json') // This file is actually called data.json
|
||||
return result["hitcount"]
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user