generated from skills/copilot-codespaces-vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
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
9c34cc0
commit e6117cf
Showing
1 changed file
with
28 additions
and
14 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 |
---|---|---|
@@ -1,21 +1,35 @@ | ||
//create web server | ||
var express = require('express'); | ||
var app = express(); | ||
//create web server and listen on port 3000 | ||
const express = require('express'); | ||
const app = express(); | ||
const port = 3000; | ||
|
||
//set the view engine to ejs | ||
app.set('view engine', 'ejs'); | ||
// import comments.js | ||
const comments = require('./comments.js'); | ||
|
||
//use res.render to load up an ejs view file | ||
// when user access the root of the website | ||
app.get('/', (req, res) => { | ||
res.send('Welcome to our website!'); | ||
}); | ||
|
||
// when user access the /comments route | ||
app.get('/comments', (req, res) => { | ||
res.json(comments); | ||
}); | ||
|
||
// index page | ||
app.get('/', function(req, res) { | ||
res.render('pages/index'); | ||
// when user access the /comments/:id route | ||
app.get('/comments/:id', (req, res) => { | ||
const id = req.params.id; | ||
const comment = comments.find((comment) => comment.id === parseInt(id)); | ||
res.json(comment); | ||
}); | ||
|
||
// about page | ||
app.get('/about', function(req, res) { | ||
res.render('pages/about'); | ||
// start the server | ||
app.listen(port, () => { | ||
console.log(`Server started on http://localhost:${port}`); | ||
}); | ||
|
||
app.listen(8080); | ||
console.log('8080 is the magic port'); | ||
// Path: comments.js | ||
//create a list of comments | ||
module.exports = [ | ||
{ | ||
id: 1, |