Remove Redis as dependency
This commit is contained in:
25
index.js
25
index.js
@@ -1,31 +1,32 @@
|
||||
const fs = require('fs'); // Filesystem Access
|
||||
const express = require('express');
|
||||
const app = express(); // Init Express
|
||||
const Redis = require('ioredis'); // Init Redis
|
||||
|
||||
const globalConfig = JSON.parse(fs.readFileSync('config.json', 'utf-8')) // Read config file
|
||||
|
||||
const db = new Redis({
|
||||
host: globalConfig.redisServer,
|
||||
port: globalConfig.redisPort
|
||||
})
|
||||
module.exports = { app, db, globalConfig } // Export database connection for other files
|
||||
module.exports = { app, globalConfig, fs } // Export express app and fs objects and globalconfig
|
||||
|
||||
app.use(express.json()) // Allows receiving JSON bodies
|
||||
// see important note: https://expressjs.com/en/api.html#express.json
|
||||
|
||||
fs.readdir(globalConfig.routesDirectory, (err, files) => {
|
||||
// Import Routes
|
||||
fs.readdir(globalConfig.startup.routesDir, (err, files) => {
|
||||
if (err) {
|
||||
console.log("FATAL: Unable to read ./routes")
|
||||
console.log(`FATAL: Unable to read ${globalConfig.startup.routesDir}`)
|
||||
process.exit(1)
|
||||
} else {
|
||||
let importedRoutes = []
|
||||
files.forEach(file => {
|
||||
importedRoutes.push(file)
|
||||
require(`${globalConfig.routesDirectory}/${file}`)
|
||||
require(`${globalConfig.startup.routesDir}/${file}`)
|
||||
importedRoutes.push(file.slice(0,-3))
|
||||
})
|
||||
console.log(`Imported Routes: ${importedRoutes}`)
|
||||
}
|
||||
})
|
||||
|
||||
console.log(`Started on ${globalConfig.apiPort}`)
|
||||
app.listen(globalConfig.apiPort);``
|
||||
app.get("/", (rreq,rres) => {
|
||||
rres.redirect(globalConfig.startup.documentationUrl)
|
||||
})
|
||||
|
||||
console.log(`Started on ${globalConfig.startup.apiPort}`)
|
||||
app.listen(globalConfig.startup.apiPort)
|
||||
Reference in New Issue
Block a user