Skip to content

Commit

Permalink
Copilot third commit
Browse files Browse the repository at this point in the history
  • Loading branch information
github-cloudlabsuser-755 committed May 17, 2024
1 parent 9c34cc0 commit e6117cf
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions comments.js
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,

0 comments on commit e6117cf

Please sign in to comment.