-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (34 loc) · 1.18 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import express from 'express';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import routes from './routes/index.js'
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import path from 'path';
console.clear()
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const port = process.env.PORT || 3100;
const app = express();
// Middleware para manejar cookies
app.use(cookieParser());
// Middleware para servir archivos estaticos
app.use(express.static(path.join(__dirname, 'public')));
//Middleware para parsear el cuerpo de la solicitud
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }));
// Configurar EJS como motor de vistas
app.set('view engine', 'ejs');
// Configurar el directorio donde están las vistas
app.set('views', path.join(__dirname, 'views'));
// Ruta para renderizar la vista dasboards.ejs
app.get('/dashboard', (req, res) => {
res.render('dashboard', { nombre: 'Mundo' });
});
app.get('/imagenes', (req, res) => {
res.render('lienzo');
});
app.use('/', routes)
app.listen(port, () => {
console.log(`Abrime => http://localhost:${port}/dashboard`);
})