-
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.
feat: changed JS-MongoDB-TypeORM-NoAuth-Template to the template
- Loading branch information
1 parent
a0be4d0
commit dbc0e85
Showing
10 changed files
with
154 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,49 @@ | ||
.vscode/ | ||
# Logs and Runtime data | ||
logs/ | ||
*.log | ||
|
||
# Dependency directories | ||
node_modules/ | ||
|
||
# Yarn and npm cache directories | ||
.yarn/cache/ | ||
.npm/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional cache directories | ||
.eslintcache | ||
.stylelintcache | ||
|
||
# Environment variables | ||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# Build output | ||
dist/ | ||
build/ | ||
out/ | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage/ | ||
|
||
# Editor-specific files | ||
.vscode/ | ||
.idea/ | ||
*.swp | ||
|
||
# Temporary files | ||
*.tmp | ||
*.temp | ||
|
||
# OS-specific files | ||
.DS_Store | ||
Thumbs.db | ||
|
||
# Miscellaneous | ||
.node_repl_history | ||
.vscode-test |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,63 @@ | ||
// 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 your files | ||
import { port } from "./config/initial.config.js"; | ||
import "./config/db.config.js"; | ||
import { port } from "./config/initialConfig.js"; | ||
import cookieParser from "cookie-parser"; | ||
import "./config/dbConfig.js"; | ||
import helloWorldRouter from "./routes/helloWorldRoutes.js"; | ||
|
||
// initializing your app | ||
// 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}`); | ||
}); | ||
|
||
|
||
|
||
|
||
|
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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,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" | ||
}); | ||
} | ||
} | ||
|
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'; | ||
|
||
const helloWorldRouter = express.Router() | ||
|
||
helloWorldRouter.get("/" , helloWorld) | ||
|
||
export default helloWorldRouter; |
This file was deleted.
Oops, something went wrong.