Skip to content
Permalink
Browse files
missing updates
  • Loading branch information
caracold committed Apr 23, 2020
1 parent ffef714 commit cadb4c60c1d00c4bb572e6bbd47ea0e090b86718
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
@@ -1 +1 @@
web: node server.js
web:node server.js
@@ -11,6 +11,6 @@ router.post('/', authCheck, msgControl.sendMessage);

router.get('/sent', authCheck, msgControl.getSent);

router.get('/:msgid', authCheck, sgControl.getMessage);
router.get('/:msgid', authCheck, msgControl.getMessage);

module.exports = router;
5 app.js
@@ -8,14 +8,17 @@ const itemRoutes = require('./api/routes/items');
const userRoutes = require('./api/routes/user');
const msgRoutes = require('./api/routes/messages');

//Method to connect the API to an existing MongoDB database
mongoose.connect(
'mongodb+srv://Caracold:304CEM-resit@cluster0-kbwm8.mongodb.net/test?retryWrites=true&w=majority', { useNewUrlParser: true, useUnifiedTopology: true })

//Setting dependencies for parsing and setting the uploads folder to public to allow access to image files.
app.use(morgan('dev'));
app.use('/uploads', express.static('uploads'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

//Middleware setting permissions to avoid browser-related errors
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');
@@ -26,6 +29,7 @@ app.use((req, res, next) => {
next();
});

//Ensuring a browser that reaches the API's homepage is redirected to an existing route
app.get('/', function(req, res) {
res.redirect('/itemlist');
});
@@ -34,6 +38,7 @@ app.use('/itemlist', itemRoutes);
app.use('/user', userRoutes);
app.use('/inbox', msgRoutes);

//Catch inexistent routes with a 404 error
app.use((req, res, next) => {
const error = new Error('Address not found');
error.status = 404;

0 comments on commit cadb4c6

Please sign in to comment.