edit server

This commit is contained in:
Francesco Esposito 2019-08-06 18:50:34 +02:00
parent 39fea74365
commit 32333cc9f6
1 changed files with 40 additions and 0 deletions

40
src/server.js Normal file
View File

@ -0,0 +1,40 @@
import express from 'express';
import bodyParser from 'body-parser';
import cors from 'cors';
import users from './routes/users';
import privateUsers from './routes/PrivateUsers';
import privateTickets from './routes/PrivateTickets';
import categories from './routes/categories';
import tickets from './routes/tickets';
import authentication from './helpers/authentication';
const mongoose = require('./config/database');
const app = express();
app.set('secretKey', 'ciccio'); // sostituire con variabili ambiente
// connection to mongodb
mongoose.connection.on('error', console.error.bind(console, 'MongoDB connection error:'));
// middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.disable('etag');
app.use(cors());
// routes
app.use('/api/users', users);
app.use('/api/tickets', tickets);
app.use('/api/categories', categories);
// private routes
app.use('/api/tickets', authentication, privateTickets);
app.use('/api/users', authentication, privateUsers);
// listen
app.listen(3001, () => {
console.log('Server started');
});