-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (34 loc) · 1.28 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const path = require('path');
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const multer = require("multer");
const upload = multer();
const recipeController = require('./recipeController');
const PORT = 3000;
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use('/', express.static(path.join(__dirname, '/client')));
app.get('/', (req, res) =>
res.sendFile(path.join(__dirname, 'client/index.html'))
); //serve index.html
app.post('/ingredients', upload.none(), recipeController.getRecipe, (req, res) => {
res.status(200).json(res.locals.recipeFound);
});
app.get('/random', upload.none(), recipeController.randomRecipe, (req, res) => {
res.status(200).json(res.locals.random);
})
app.use((req, res) => res.sendStatus(404));
// Global error handler
// app.use((err, req, res, next) => {
// const defaultErr = {
// log: 'Express error handler caught unknown middleware error',
// status: 400,
// message: { err: 'An error occurred' },
// };
// const errorObj = Object.assign({}, defaultErr, err);
// console.log(errorObj.log);
// return res.status(errorObj.status).json(errorObj.message);
// });
app.listen(PORT, () => console.log(`Listening on PORT: ${PORT}`));
module.exports = app;