json parsing middleware
This commit is contained in:
@@ -1,15 +1,16 @@
|
|||||||
import express from 'express';
|
import express, {json} from 'express';
|
||||||
import ProductsRoutes from './routes/products/index'
|
import productsRoutes from './routes/products/index'
|
||||||
|
|
||||||
const app = express();
|
|
||||||
const port = 3000;
|
const port = 3000;
|
||||||
|
const app = express();
|
||||||
|
app.use(json());
|
||||||
|
|
||||||
app.get('/', (req, res) => {
|
app.get('/', (req, res) => {
|
||||||
res.send('Hello World! 123');
|
res.send('Hello World! 123');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
app.use ('/products', ProductsRoutes);
|
app.use ('/products', productsRoutes);
|
||||||
|
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`Example app listening on port ${port}`);
|
console.log(`Example app listening on port ${port}`);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { listProducts,
|
|||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
// products endpoints
|
// products endpoints where validator can be added later
|
||||||
router.get('/', listProducts);
|
router.get('/', listProducts);
|
||||||
router.get('/:id', getProductById);
|
router.get('/:id', getProductById);
|
||||||
router.post('/', createProduct);
|
router.post('/', createProduct);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export function getProductById(req: Request, res: Response) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function createProduct(req: Request, res: Response) {
|
export function createProduct(req: Request, res: Response) {
|
||||||
|
console.log (req.body);
|
||||||
res.send ('createProduct');
|
res.send ('createProduct');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user