Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3f3405
commit 2f52413
Showing
8 changed files
with
1,172 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
PORT=3000 | ||
MONGO_URI=mongodb://localhost:27017/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Responds with a JSON object containing the message "Hello, World!". | ||
* @param {Request} req - The request object. | ||
* @param {Response} res - The response object. | ||
*/ | ||
function getHelloWorld(req, res) { | ||
// Extract request details | ||
const requestDetails = { | ||
method: req.method, | ||
url: req.url, | ||
headers: req.headers, | ||
params: req.params, | ||
query: req.query, | ||
body: req.body | ||
}; | ||
|
||
// Create a message object | ||
const message = { | ||
message: "Hello, World!" | ||
}; | ||
|
||
// Send the message as JSON | ||
res.json({ | ||
...requestDetails, | ||
...message | ||
}); | ||
} | ||
|
||
|
||
module.exports = { | ||
getHelloWorld, | ||
}; |
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,15 @@ | ||
// Routes/api.js | ||
|
||
const express = require('express'); | ||
const router = express.Router(); | ||
|
||
// Import the HelloWorld controller | ||
const helloWorldController = require('../Controllers/HelloWorld'); | ||
|
||
|
||
// Define a sample API route using the controller | ||
router.get('/', helloWorldController.getHelloWorld); | ||
|
||
// Define other API routes as needed | ||
|
||
module.exports = router; |
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,11 @@ | ||
// Routes/views.js | ||
|
||
const express = require('express'); | ||
const router = express.Router(); | ||
|
||
// Serve the index.html file for the root path with cache control set to 5 minutes | ||
router.use('/', express.static('Views', { index: 'index.html', maxAge: '5m' })); | ||
|
||
// Define other view routes as needed | ||
|
||
module.exports = router; |
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,46 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Congratulations Page</title> | ||
<style> | ||
body { | ||
font-family: 'Arial', sans-serif; | ||
margin: 0; | ||
padding: 0; | ||
background: linear-gradient(to right, #4a69bb, #283c86); | ||
color: #fff; | ||
text-align: center; | ||
min-height: 100vh; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.container { | ||
max-width: 600px; | ||
padding: 40px; | ||
background-color: rgba(255, 255, 255, 0.95); | ||
border-radius: 20px; | ||
box-shadow: 0 0 20px rgba(0, 0, 0, 0.2); | ||
} | ||
|
||
h1 { | ||
color: #4a69bb; | ||
} | ||
|
||
p { | ||
color: #333; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
||
<div class="container"> | ||
<h1>Congratulations!</h1> | ||
<p>You have successfully created @ngtv/create-node-app</p> | ||
</div> | ||
|
||
</body> | ||
</html> |
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,28 @@ | ||
// Import the required modules | ||
const express = require('express'); | ||
|
||
// Create an instance of the Express application | ||
const app = express(); | ||
|
||
// Set the port to the value specified in the environment variable, or default to 3000 | ||
const port = process.env.PORT || 3000; | ||
|
||
// Set the host to the value specified in the environment variable, or default to 'localhost' | ||
const host = process.env.HOST || 'localhost'; | ||
|
||
// Import the routes for views and API | ||
const viewsRoutes = require('./Routes/views'); | ||
const apiRoutes = require('./Routes/api'); | ||
|
||
// Use the views routes for the root path | ||
app.use('/', viewsRoutes); | ||
|
||
// Use the API routes for the '/api' path | ||
app.use('/api', apiRoutes); | ||
|
||
// Start the server and listen on the specified port and host | ||
app.listen(port, () => { | ||
console.log(`Server running at http://${host}:${port}/`); | ||
}); | ||
|
||
// End of the code |
Oops, something went wrong.