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