From 32333cc9f65fbfb1b2804906d69a379ea71010c0 Mon Sep 17 00:00:00 2001 From: Francesco Esposito <33671357+frsposito@users.noreply.github.com> Date: Tue, 6 Aug 2019 18:50:34 +0200 Subject: [PATCH] edit server --- src/server.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/server.js diff --git a/src/server.js b/src/server.js new file mode 100644 index 0000000..e8581ba --- /dev/null +++ b/src/server.js @@ -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'); +});