This repository has been archived by the owner on Jan 31, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #450 from sharafdin/tman
Tman
- Loading branch information
Showing
8 changed files
with
64 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 44 additions & 3 deletions
47
packages/yonode-templates/JS-PostgreSQL-Prisma-NoAuth-Template/src/app.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,58 @@ | ||
// import the packages | ||
import express from "express"; | ||
import chalk from "chalk"; | ||
import helmet from "helmet"; | ||
import cors from "cors"; | ||
import morgan from "morgan"; | ||
import rateLimit from "express-rate-limit"; | ||
import compression from "compression"; | ||
import cookieParser from "cookie-parser"; | ||
|
||
// import your files | ||
import { port } from "./config/initial.config.js"; | ||
import { port } from "./config/initialConfig.js"; | ||
import helloWorldRouter from "./routes/helloWorldRoutes.js"; | ||
|
||
// Initializing the app | ||
const app = express(); | ||
app.use(cookieParser()); | ||
// Essential security headers with Helmet | ||
app.use(helmet()); | ||
|
||
// Enable CORS with default settings | ||
app.use(cors()); | ||
|
||
// Logger middleware for development environment | ||
if (process.env.NODE_ENV === "development") { | ||
app.use(morgan("dev")); | ||
} | ||
|
||
app.use(compression()); // Compress all routes | ||
|
||
// Rate limiting to prevent brute-force attacks | ||
const limiter = rateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 100, // limit each IP to 100 requests per windowMs | ||
}); | ||
app.use(limiter); | ||
|
||
// Built-in middleware for parsing JSON | ||
app.use(express.json()); | ||
|
||
// rest of your code here | ||
// Use your routes here | ||
app.use("/api/helloworld", helloWorldRouter); | ||
|
||
// Global error handler | ||
app.use((err, req, res, next) => { | ||
console.error(chalk.red(err.stack)); | ||
res.status(err.status || 500).json({ | ||
message: err.message || "Internal Server Error", | ||
error: {}, | ||
}); | ||
}); | ||
|
||
|
||
|
||
|
||
app.listen(port, () => { | ||
console.log(`${chalk.green.bold("Server")} is listening on port ${port}`); | ||
}); | ||
}); |
File renamed without changes.
7 changes: 0 additions & 7 deletions
7
packages/yonode-templates/JS-PostgreSQL-Prisma-NoAuth-Template/src/controllers/controller.js
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
...de-templates/JS-PostgreSQL-Prisma-NoAuth-Template/src/controllers/helloWorldController.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
}); | ||
} | ||
}; |
8 changes: 8 additions & 0 deletions
8
...ages/yonode-templates/JS-PostgreSQL-Prisma-NoAuth-Template/src/routes/helloWorldRoutes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import express from "express"; | ||
import { helloWorld } from "../controllers/helloWorldController.js"; | ||
|
||
const helloWorldRouter = express.Router(); | ||
|
||
helloWorldRouter.get("/", helloWorld); | ||
|
||
export default helloWorldRouter; |
5 changes: 0 additions & 5 deletions
5
packages/yonode-templates/JS-PostgreSQL-Prisma-NoAuth-Template/src/routes/router.js
This file was deleted.
Oops, something went wrong.