Atualizado

This commit is contained in:
Luiz F Picolo 2024-10-24 21:23:09 -04:00
parent 982c618c13
commit d04b382ea6
7 changed files with 73 additions and 15 deletions

2
app.js
View File

@ -6,6 +6,7 @@ var logger = require('morgan');
var homeRouter = require('./routes/home'); var homeRouter = require('./routes/home');
var autenicarRouter = require('./routes/autenticar'); var autenicarRouter = require('./routes/autenticar');
var produtosRouter = require('./routes/produtos');
var app = express(); var app = express();
@ -21,6 +22,7 @@ app.use(express.static(path.join(__dirname, 'public')));
app.use('/', homeRouter); app.use('/', homeRouter);
app.use('/autenticar', autenicarRouter); app.use('/autenticar', autenicarRouter);
app.use('/produtos', produtosRouter);
// catch 404 and forward to error handler // catch 404 and forward to error handler
app.use(function(req, res, next) { app.use(function(req, res, next) {

View File

@ -0,0 +1,14 @@
const listar = function(req, res){
res.render('produtos/listar', {
title: "Titulo"
})
}
const visualizar = function(req, res){
const id = req.params.id
res.render('produtos/visualizar', {
titulo: id
})
}
module.exports = { listar, visualizar }

32
package-lock.json generated
View File

@ -317,19 +317,21 @@
} }
}, },
"node_modules/cookie": { "node_modules/cookie": {
"version": "0.4.1", "version": "0.7.2",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
"integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==", "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
"license": "MIT",
"engines": { "engines": {
"node": ">= 0.6" "node": ">= 0.6"
} }
}, },
"node_modules/cookie-parser": { "node_modules/cookie-parser": {
"version": "1.4.6", "version": "1.4.7",
"resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.6.tgz", "resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.7.tgz",
"integrity": "sha512-z3IzaNjdwUC2olLIB5/ITd0/setiaFMLYiZJle7xg5Fe9KWAceil7xszYfHHBtDFYLSgJduS2Ty0P1uJdPDJeA==", "integrity": "sha512-nGUvgXnotP3BsjiLX2ypbQnWoGUPIIfHQNZkkC668ntrzGWEZVW70HDEB1qnNGMicPje6EttlIgzo51YSwNQGw==",
"license": "MIT",
"dependencies": { "dependencies": {
"cookie": "0.4.1", "cookie": "0.7.2",
"cookie-signature": "1.0.6" "cookie-signature": "1.0.6"
}, },
"engines": { "engines": {
@ -442,16 +444,17 @@
} }
}, },
"node_modules/express": { "node_modules/express": {
"version": "4.21.0", "version": "4.21.1",
"resolved": "https://registry.npmjs.org/express/-/express-4.21.0.tgz", "resolved": "https://registry.npmjs.org/express/-/express-4.21.1.tgz",
"integrity": "sha512-VqcNGcj/Id5ZT1LZ/cfihi3ttTn+NJmkli2eZADigjq29qTlWi/hAQ43t/VLPq8+UX06FCEx3ByOYet6ZFblng==", "integrity": "sha512-YSFlK1Ee0/GC8QaO91tHcDxJiE/X4FbpAyQWkxAvG6AXCuR65YzK8ua6D9hvi/TzUfZMpc+BwuM1IPw8fmQBiQ==",
"license": "MIT",
"dependencies": { "dependencies": {
"accepts": "~1.3.8", "accepts": "~1.3.8",
"array-flatten": "1.1.1", "array-flatten": "1.1.1",
"body-parser": "1.20.3", "body-parser": "1.20.3",
"content-disposition": "0.5.4", "content-disposition": "0.5.4",
"content-type": "~1.0.4", "content-type": "~1.0.4",
"cookie": "0.6.0", "cookie": "0.7.1",
"cookie-signature": "1.0.6", "cookie-signature": "1.0.6",
"debug": "2.6.9", "debug": "2.6.9",
"depd": "2.0.0", "depd": "2.0.0",
@ -483,9 +486,10 @@
} }
}, },
"node_modules/express/node_modules/cookie": { "node_modules/express/node_modules/cookie": {
"version": "0.6.0", "version": "0.7.1",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.1.tgz",
"integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==", "integrity": "sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==",
"license": "MIT",
"engines": { "engines": {
"node": ">= 0.6" "node": ">= 0.6"
} }

View File

@ -1,6 +1,6 @@
var express = require('express'); var express = require('express');
var router = express.Router(); var router = express.Router();
const { home } = require('../controllers/homeController') const { home } = require('../controllers/homeController');
/* GET home page. */ /* GET home page. */
router.get('/', home); router.get('/', home);

9
routes/produtos.js Normal file
View File

@ -0,0 +1,9 @@
var express = require('express');
var router = express.Router();
const { listar, visualizar } = require('../controllers/produtosController');
router.get('/', listar);
router.get('/:id', visualizar);
router.get('/busca', visualizar);
module.exports = router;

17
views/produtos/listar.ejs Normal file
View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/stylesheets/style.css">
<title>Produtos</title>
</head>
<body>
<h1>Produtos</h1>
<ul>
<li><a href="/produtos/produto-1"> Produto 1</a></li>
<li><a href="/produtos/produto-2"> Produto 2</a></li>
<li><a href="/produtos/produto-3"> Produto 3</a></li>
</ul>
</body>
</html>

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/stylesheets/style.css">
<title>Produtos</title>
</head>
<body>
<h1><%= titulo %></h1>
</body>
</html>