diff --git a/server/src/config/env.js b/server/src/config/env.js index 6b4db67a..d5f75fcb 100644 --- a/server/src/config/env.js +++ b/server/src/config/env.js @@ -1,37 +1,38 @@ -require('dotenv').config() -const env = process.env.NODE_ENV || 'development' +require("dotenv").config(); +const env = process.env ?? process.secrets; +const mode = env.NODE_ENV || "development"; // common environmental variables for all environments const common = { - PORT: process.env.PORT || 3600, - GIPHY_API_KEY: 'dqp8GYkt1VqBk7GjiuKUYj4QdbJS4phJ', -} + PORT: env.PORT || 3600, + GIPHY_API_KEY: env.GIPHY_API_KEY, +}; // environmental variables for development const development = { - NODE_ENV: 'development', - DB_URI: 'mongodb://localhost:27017/hobbes', + NODE_ENV: "development", + DB_URI: "mongodb://localhost:27017/hobbes", ...common, -} +}; // environmental variables for production const production = { - NODE_ENV: 'production', - DB_URI: process.env.DB_URI, + NODE_ENV: "production", + DB_URI: env.DB_URI, ...common, -} +}; // environmental variables for testing const test = { - NODE_ENV: 'test', - DB_URI: 'mongodb://localhost:27017/hobbes_test', + NODE_ENV: "test", + DB_URI: "mongodb://localhost:27017/hobbes_test", ...common, -} +}; const config = { development, production, test, -} +}; -module.exports = config[env] +module.exports = config[mode]; diff --git a/server/src/controllers/plugin-info.js b/server/src/controllers/plugin-info.js index 89ddbb95..c01966d1 100644 --- a/server/src/controllers/plugin-info.js +++ b/server/src/controllers/plugin-info.js @@ -1,12 +1,12 @@ -const response = require('../utils/response') +const response = require("../utils/response"); class PluginInfoController { async getInfo(req, res) { const info = `The company online tools plugin is a feature which allows users to interact with third party tools like Google Drive, Figma, Github, etc. to make work flow for themselves or their team faster and easier. - All our tools are external applications that you may have used or heard of but to maximize productivity, we are giving you access to some of their awesome features right in Zuri Chat.` + All our tools are external applications that you may have used or heard of but to maximize productivity, we are giving you access to some of their awesome features right in Zuri Chat.`; - res.send(response('Plugin Info returned successfully', info)) + res.send(response("Plugin Info returned successfully", info)); } } -module.exports = new PluginInfoController() +module.exports = new PluginInfoController(); diff --git a/server/src/controllers/sidebar.js b/server/src/controllers/sidebar.js new file mode 100644 index 00000000..1f2f4ebc --- /dev/null +++ b/server/src/controllers/sidebar.js @@ -0,0 +1,16 @@ +const response = require("../utils/response"); + +class SidebarController { + async getSideBarEndpoints(req, res) { + const endpoints = ["/gmail", "github", "figma", "google-drive", "giphy"]; + + res.send( + response( + "Sidebar endpoints for Online Tools returned successfully", + endpoints + ) + ); + } +} + +module.exports = new SidebarController(); diff --git a/server/src/routes/giphy.js b/server/src/routes/giphy.js index ad67e36f..2613bc58 100644 --- a/server/src/routes/giphy.js +++ b/server/src/routes/giphy.js @@ -1,10 +1,10 @@ -const router = require('express').Router() -const giphy = require('../controllers/giphy') +const router = require("express").Router(); +const giphy = require("../controllers/giphy"); module.exports = function () { - router.get('/random', giphy.randomGif) + router.get("/giphy/random", giphy.randomGif); - router.get('/trending', giphy.trendingGifs) + router.get("/giphy/trending", giphy.trendingGifs); - return router -} + return router; +}; diff --git a/server/src/routes/googledrive/index.js b/server/src/routes/googledrive/index.js index 7005977d..eca6a6ef 100644 --- a/server/src/routes/googledrive/index.js +++ b/server/src/routes/googledrive/index.js @@ -3,7 +3,7 @@ const router = require("express").Router(); const googleDrvieController = require("../../controllers/googledrive/index"); module.exports = function () { - router.get("/", googleDrvieController.index); + router.get("/googledrive", googleDrvieController.index); return router; }; diff --git a/server/src/routes/index.js b/server/src/routes/index.js index e5854eea..542ca213 100644 --- a/server/src/routes/index.js +++ b/server/src/routes/index.js @@ -1,11 +1,19 @@ -const router = require('express').Router() -const pluginInfoRouter = require('./plugin-info') -const giphy = require('./giphy') +const router = require("express").Router(); +const pluginInfoRouter = require("./plugin-info"); const googleDriveApi = require("./googledrive"); +const sideBarRouter = require("./sidebar"); +const giphy = require("./giphy"); module.exports = () => { - router.use('/giphy', giphy()) - router.use(pluginInfoRouter()) - router.use('/googledrive',googleDriveApi()); - return router -} + router.use(pluginInfoRouter()); + router.use(googleDriveApi()); + router.use(sideBarRouter()); + router.use(giphy()); + + // Handle Invalid API routes + router.use((req, res, next) => { + next(new NotFoundError()); + }); + + return router; +}; diff --git a/server/src/routes/sidebar.js b/server/src/routes/sidebar.js new file mode 100644 index 00000000..166525d3 --- /dev/null +++ b/server/src/routes/sidebar.js @@ -0,0 +1,9 @@ +const router = require("express").Router(); + +const sideBarController = require("../controllers/sidebar"); + +module.exports = function () { + router.get("/sidebar", sideBarController.getSideBarEndpoints); + + return router; +};