-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
34 lines (26 loc) · 1.08 KB
/
server.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
const express = require('express'); //Framework Express
const bodyParser = require('body-parser'); //Parsea el post para obtener objetos json en el request
const levelup = require('levelup'); // Base de datos
const morgan = require('morgan'); // Sistema de logging (muestra en la cosa los request)
const morganjson = require('morgan-json');
const apiUsers = require('./api/users'); //Endpoints relacionados al User model
const app = express();
const db = levelup('./data/users', {valueEncoding: 'json'});
const format = morganjson({
short: ':method :url :status',
length: ':res[content-length]',
'response-time': ':response-time ms'
});
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(express.static('public'));
app.use(morgan(format));
let router = express.Router();
router.get('/', (req, res) => {
res.json({ name: 'yape-api',version: "0.0.1"});
});
app.use('/api',apiUsers(router,db));
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log('Server running on port '+port+'!');
});