diff --git a/packages/yonode-templates/JS-MongoDB-Prisma-NoAuth-Template/src/app.js b/packages/yonode-templates/JS-MongoDB-Prisma-NoAuth-Template/src/app.js index d02ae925..7cc0fc4e 100644 --- a/packages/yonode-templates/JS-MongoDB-Prisma-NoAuth-Template/src/app.js +++ b/packages/yonode-templates/JS-MongoDB-Prisma-NoAuth-Template/src/app.js @@ -9,6 +9,13 @@ import { port } from "./config/initial.config.js"; const app = express(); app.use(express.json()); + +// use your routes here + +app.use("/api/helloworld", helloWorldRouter); + + + // rest of your code here diff --git a/packages/yonode-templates/JS-MongoDB-Prisma-NoAuth-Template/src/controllers/controller.js b/packages/yonode-templates/JS-MongoDB-Prisma-NoAuth-Template/src/controllers/controller.js deleted file mode 100644 index 6b230749..00000000 --- a/packages/yonode-templates/JS-MongoDB-Prisma-NoAuth-Template/src/controllers/controller.js +++ /dev/null @@ -1,7 +0,0 @@ -export const controller = async (req, res) => { - try { - - } catch (error) { - - } -}; \ No newline at end of file diff --git a/packages/yonode-templates/JS-MongoDB-Prisma-NoAuth-Template/src/controllers/helloWorldController.js b/packages/yonode-templates/JS-MongoDB-Prisma-NoAuth-Template/src/controllers/helloWorldController.js new file mode 100644 index 00000000..107fb387 --- /dev/null +++ b/packages/yonode-templates/JS-MongoDB-Prisma-NoAuth-Template/src/controllers/helloWorldController.js @@ -0,0 +1,9 @@ +export const helloWorld = async (req, res) => { + try { + res.send("Hello World!"); + } catch (error) { + res.status(500).json({ + message: "Internal Server Error", + }); + } + }; \ No newline at end of file diff --git a/packages/yonode-templates/JS-MongoDB-Prisma-NoAuth-Template/src/routes/helloWorldRoutes.js b/packages/yonode-templates/JS-MongoDB-Prisma-NoAuth-Template/src/routes/helloWorldRoutes.js new file mode 100644 index 00000000..ff85ddba --- /dev/null +++ b/packages/yonode-templates/JS-MongoDB-Prisma-NoAuth-Template/src/routes/helloWorldRoutes.js @@ -0,0 +1,8 @@ +import express from "express"; +import { helloWorld } from "../controllers/helloWorldController.js"; + +const helloWorldRouter = express.Router(); + +helloWorldRouter.get("/", helloWorld); + +export default helloWorldRouter; diff --git a/packages/yonode-templates/JS-MongoDB-Prisma-NoAuth-Template/src/routes/router.js b/packages/yonode-templates/JS-MongoDB-Prisma-NoAuth-Template/src/routes/router.js deleted file mode 100644 index 2c054c51..00000000 --- a/packages/yonode-templates/JS-MongoDB-Prisma-NoAuth-Template/src/routes/router.js +++ /dev/null @@ -1,5 +0,0 @@ -import express from "express"; - -const routerName = express.Router(); - -export default routerName; diff --git a/packages/yonode-templates/JS-MongoDB-TypeORM-NoAuth-Template/src/app.js b/packages/yonode-templates/JS-MongoDB-TypeORM-NoAuth-Template/src/app.js index 063906f9..d85463d8 100644 --- a/packages/yonode-templates/JS-MongoDB-TypeORM-NoAuth-Template/src/app.js +++ b/packages/yonode-templates/JS-MongoDB-TypeORM-NoAuth-Template/src/app.js @@ -10,6 +10,9 @@ import "./config/db.config.js"; const app = express(); app.use(express.json()); +// Use Your Route here +pp.use("/api/helloworld", helloWorldRouter); + // rest of your code here diff --git a/packages/yonode-templates/JS-MongoDB-TypeORM-NoAuth-Template/src/controllers/controller.js b/packages/yonode-templates/JS-MongoDB-TypeORM-NoAuth-Template/src/controllers/controller.js deleted file mode 100644 index e641c1a7..00000000 --- a/packages/yonode-templates/JS-MongoDB-TypeORM-NoAuth-Template/src/controllers/controller.js +++ /dev/null @@ -1,7 +0,0 @@ -export const controller = async (req, res) => { - try { - - } catch (error) { - - } -}; \ No newline at end of file diff --git a/packages/yonode-templates/JS-MongoDB-TypeORM-NoAuth-Template/src/controllers/helloWorldController.js b/packages/yonode-templates/JS-MongoDB-TypeORM-NoAuth-Template/src/controllers/helloWorldController.js new file mode 100644 index 00000000..510b46cc --- /dev/null +++ b/packages/yonode-templates/JS-MongoDB-TypeORM-NoAuth-Template/src/controllers/helloWorldController.js @@ -0,0 +1,25 @@ +/** + * Hello World controller + * + * This is a simple controller that returns a "Hello World" message + * in the response body. It is a good example of how to create a basic + * controller in Yonode. + * + * @param {Object} res The Express.js response object + * @param {Object} req The Express.js request object + */ +export const helloWorld = async (res, req) => { + try { + + // Send a "Hello World" message in the response body + res.send("Hello World"); + + } catch (err) { + // If there is an error, send a 500 Internal Server Error + // with a message in the response body + res.status(500).json({ + message: "Internal Server Error" + }); + } +} + diff --git a/packages/yonode-templates/JS-MongoDB-TypeORM-NoAuth-Template/src/routes/helloWorldRoutes.js b/packages/yonode-templates/JS-MongoDB-TypeORM-NoAuth-Template/src/routes/helloWorldRoutes.js new file mode 100644 index 00000000..867a3111 --- /dev/null +++ b/packages/yonode-templates/JS-MongoDB-TypeORM-NoAuth-Template/src/routes/helloWorldRoutes.js @@ -0,0 +1,8 @@ +import express from 'express' +import { helloWorld } from '../controllers/helloWorldController'; + +const helloWorldRouter = express.Router() + +helloWorldRouter.get("/" , helloWorld) + +export default helloWorldRouter; \ No newline at end of file diff --git a/packages/yonode-templates/JS-MongoDB-TypeORM-NoAuth-Template/src/routes/router.js b/packages/yonode-templates/JS-MongoDB-TypeORM-NoAuth-Template/src/routes/router.js deleted file mode 100644 index 18b49770..00000000 --- a/packages/yonode-templates/JS-MongoDB-TypeORM-NoAuth-Template/src/routes/router.js +++ /dev/null @@ -1,5 +0,0 @@ -import express from "express"; - -const routerName = express.Router(); - -export default routerName; \ No newline at end of file diff --git a/packages/yonode-templates/JS-MySQL-Prisma-NoAuth-Template/src/app.js b/packages/yonode-templates/JS-MySQL-Prisma-NoAuth-Template/src/app.js index 31f5f275..ec760c74 100644 --- a/packages/yonode-templates/JS-MySQL-Prisma-NoAuth-Template/src/app.js +++ b/packages/yonode-templates/JS-MySQL-Prisma-NoAuth-Template/src/app.js @@ -11,6 +11,9 @@ app.use(express.json()); // rest of your code here +// Use you Routes here +pp.use("/api/helloworld", helloWorldRouter); + app.listen(port, () => { console.log(`${chalk.green.bold("Server")} is listening on port ${port}`); diff --git a/packages/yonode-templates/JS-MySQL-Prisma-NoAuth-Template/src/controllers/controller.js b/packages/yonode-templates/JS-MySQL-Prisma-NoAuth-Template/src/controllers/controller.js deleted file mode 100644 index 3252cc1d..00000000 --- a/packages/yonode-templates/JS-MySQL-Prisma-NoAuth-Template/src/controllers/controller.js +++ /dev/null @@ -1,7 +0,0 @@ -export const controller = async (req, res) => { - try { - - } catch (error) { - - } -}; \ No newline at end of file diff --git a/packages/yonode-templates/JS-MySQL-Prisma-NoAuth-Template/src/controllers/helloWorldController.js b/packages/yonode-templates/JS-MySQL-Prisma-NoAuth-Template/src/controllers/helloWorldController.js new file mode 100644 index 00000000..59bcb4ac --- /dev/null +++ b/packages/yonode-templates/JS-MySQL-Prisma-NoAuth-Template/src/controllers/helloWorldController.js @@ -0,0 +1,11 @@ +export const hellWorld = async (res, req)=>{ + try{ + + res.send("Hello world!") + + }catch(err){ + res.status(500).json({ + message: "Internal Server Error" + }) + } +} \ No newline at end of file diff --git a/packages/yonode-templates/JS-MySQL-Prisma-NoAuth-Template/src/routes/helloWorldRoutes.js b/packages/yonode-templates/JS-MySQL-Prisma-NoAuth-Template/src/routes/helloWorldRoutes.js new file mode 100644 index 00000000..f8df2dae --- /dev/null +++ b/packages/yonode-templates/JS-MySQL-Prisma-NoAuth-Template/src/routes/helloWorldRoutes.js @@ -0,0 +1,8 @@ +import express from 'express' +import { hellWorld } from '../controllers/helloWorldController.js' + +const hellWorldRouter = express.Router() + +hellWorldRouter.get("/", hellWorld) + +export default hellWorldRouter; \ No newline at end of file diff --git a/packages/yonode-templates/JS-MySQL-Prisma-NoAuth-Template/src/routes/router.js b/packages/yonode-templates/JS-MySQL-Prisma-NoAuth-Template/src/routes/router.js deleted file mode 100644 index 18b49770..00000000 --- a/packages/yonode-templates/JS-MySQL-Prisma-NoAuth-Template/src/routes/router.js +++ /dev/null @@ -1,5 +0,0 @@ -import express from "express"; - -const routerName = express.Router(); - -export default routerName; \ No newline at end of file diff --git a/packages/yonode-templates/JS-MySQL-TypeORM-NoAuth-Template/src/app.js b/packages/yonode-templates/JS-MySQL-TypeORM-NoAuth-Template/src/app.js index c9e45805..8e0e7c7f 100644 --- a/packages/yonode-templates/JS-MySQL-TypeORM-NoAuth-Template/src/app.js +++ b/packages/yonode-templates/JS-MySQL-TypeORM-NoAuth-Template/src/app.js @@ -10,6 +10,11 @@ import "./config/db.config.js"; const app = express(); app.use(express.json()); + +// Use Your Route here + +pp.use("/api/helloworld", helloWorldRouter); + // rest of your code here diff --git a/packages/yonode-templates/JS-MySQL-TypeORM-NoAuth-Template/src/controllers/controller.js b/packages/yonode-templates/JS-MySQL-TypeORM-NoAuth-Template/src/controllers/controller.js deleted file mode 100644 index e641c1a7..00000000 --- a/packages/yonode-templates/JS-MySQL-TypeORM-NoAuth-Template/src/controllers/controller.js +++ /dev/null @@ -1,7 +0,0 @@ -export const controller = async (req, res) => { - try { - - } catch (error) { - - } -}; \ No newline at end of file diff --git a/packages/yonode-templates/JS-MySQL-TypeORM-NoAuth-Template/src/controllers/helloWorldController.js b/packages/yonode-templates/JS-MySQL-TypeORM-NoAuth-Template/src/controllers/helloWorldController.js new file mode 100644 index 00000000..b9364a86 --- /dev/null +++ b/packages/yonode-templates/JS-MySQL-TypeORM-NoAuth-Template/src/controllers/helloWorldController.js @@ -0,0 +1,18 @@ +/** + * A simple controller function to handle requests to the '/' route + * @param {object} req The request object + * @param {object} res The response object + * @returns {object} The response object + */ +export const helloWorld = async (req, res) => { + try { + // Send a response to the client + res.send("Hello world!"); + } catch (err) { + // If there is an error, send a 500 error with a JSON response + res.status(500).json({ + message: "Internal Server Error", + }); + } +}; + diff --git a/packages/yonode-templates/JS-MySQL-TypeORM-NoAuth-Template/src/routes/helloWorldRoutes.js b/packages/yonode-templates/JS-MySQL-TypeORM-NoAuth-Template/src/routes/helloWorldRoutes.js new file mode 100644 index 00000000..43619c06 --- /dev/null +++ b/packages/yonode-templates/JS-MySQL-TypeORM-NoAuth-Template/src/routes/helloWorldRoutes.js @@ -0,0 +1,8 @@ +import express from 'express' +import { helloWorld } from '../controllers/helloWorldController.js' + +const helloWorldRouter = express.Router() + +helloWorldRouter.get("/", helloWorld) + +export default helloWorldRouter; \ No newline at end of file diff --git a/packages/yonode-templates/JS-MySQL-TypeORM-NoAuth-Template/src/routes/router.js b/packages/yonode-templates/JS-MySQL-TypeORM-NoAuth-Template/src/routes/router.js deleted file mode 100644 index 18b49770..00000000 --- a/packages/yonode-templates/JS-MySQL-TypeORM-NoAuth-Template/src/routes/router.js +++ /dev/null @@ -1,5 +0,0 @@ -import express from "express"; - -const routerName = express.Router(); - -export default routerName; \ No newline at end of file diff --git a/packages/yonode-templates/JS-PostgreSQL-Sequelize-NoAuth-Template/src/app.js b/packages/yonode-templates/JS-PostgreSQL-Sequelize-NoAuth-Template/src/app.js index c83b05a9..7e6ca22f 100644 --- a/packages/yonode-templates/JS-PostgreSQL-Sequelize-NoAuth-Template/src/app.js +++ b/packages/yonode-templates/JS-PostgreSQL-Sequelize-NoAuth-Template/src/app.js @@ -11,6 +11,9 @@ import './models/models.js'; const app = express(); app.use(express.json()); +// User Your Routes here +app.use("/api/helloworld", helloWorldRouter); + // rest of your code here diff --git a/packages/yonode-templates/JS-PostgreSQL-Sequelize-NoAuth-Template/src/controllers/controller.js b/packages/yonode-templates/JS-PostgreSQL-Sequelize-NoAuth-Template/src/controllers/controller.js deleted file mode 100644 index 3252cc1d..00000000 --- a/packages/yonode-templates/JS-PostgreSQL-Sequelize-NoAuth-Template/src/controllers/controller.js +++ /dev/null @@ -1,7 +0,0 @@ -export const controller = async (req, res) => { - try { - - } catch (error) { - - } -}; \ No newline at end of file diff --git a/packages/yonode-templates/JS-PostgreSQL-Sequelize-NoAuth-Template/src/controllers/helloWorldController.js b/packages/yonode-templates/JS-PostgreSQL-Sequelize-NoAuth-Template/src/controllers/helloWorldController.js new file mode 100644 index 00000000..a2c8eca7 --- /dev/null +++ b/packages/yonode-templates/JS-PostgreSQL-Sequelize-NoAuth-Template/src/controllers/helloWorldController.js @@ -0,0 +1,13 @@ + +export const helloWorld = async (res, req) => { + try { + // Send a simple string as a response + res.send("Hello World!") + } catch (err) { + // If there's an error, send a response with a 500 status code + // and an error message + res.status(500).json({ + message: "Internal Server Error" + }) + } +} diff --git a/packages/yonode-templates/JS-PostgreSQL-Sequelize-NoAuth-Template/src/routes/helloWorldRoutes.js b/packages/yonode-templates/JS-PostgreSQL-Sequelize-NoAuth-Template/src/routes/helloWorldRoutes.js new file mode 100644 index 00000000..66a5c47f --- /dev/null +++ b/packages/yonode-templates/JS-PostgreSQL-Sequelize-NoAuth-Template/src/routes/helloWorldRoutes.js @@ -0,0 +1,8 @@ +import express from "express" +import { helloWorld } from "../controllers/helloWorldController.js" + +const hellWorldRouter = express.Router() + +hellWorldRouter.get("/" , helloWorld) + +export default hellWorldRouter; diff --git a/packages/yonode-templates/JS-PostgreSQL-Sequelize-NoAuth-Template/src/routes/router.js b/packages/yonode-templates/JS-PostgreSQL-Sequelize-NoAuth-Template/src/routes/router.js deleted file mode 100644 index 18b49770..00000000 --- a/packages/yonode-templates/JS-PostgreSQL-Sequelize-NoAuth-Template/src/routes/router.js +++ /dev/null @@ -1,5 +0,0 @@ -import express from "express"; - -const routerName = express.Router(); - -export default routerName; \ No newline at end of file