-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
47 lines (36 loc) · 1.28 KB
/
app.js
File metadata and controls
47 lines (36 loc) · 1.28 KB
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
45
46
47
//paquetes
import express from 'express';
import morgan from 'morgan';
import cors from 'cors';
import path from 'path';
import mongoose from 'mongoose';
import history from'connect-history-api-fallback';
import NotasRout from './routers/NotasRout.js';
import Registros from './routers/Login.js';
const app = express();
// Obteniendo el directorio base usando import.meta.url
const __dirname = path.dirname(new URL(import.meta.url).pathname);
//conexion DB Mongo
const uri = 'mongodb://mongodb:27017/myapp';
const options = {useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true};
mongoose.connect(uri, options).then(
() => { console.log("Conexion exitosa"); },
err => { console.log(err); }
);
//Middeleware
app.use(morgan('tiny'));
app.use(cors());
app.use(express.json());
//application/x-www-form-urlencoded
app.use(express.urlencoded({ extended: true }));
//Rutas
app.use('/api', NotasRout);
app.use('/api/registros', Registros);
// Middleware para Vue.js router modo history
// const history = require('connect-history-api-fallback');
app.use(history());
app.use(express.static(path.join(__dirname, 'public')));
app.set('puerto', process.env.PORT || 3000);
app.listen(app.get('puerto'), function () {
console.log('Example app listening on port: '+ app.get('puerto'));
});