|
O‘zbekiston respublikasi axborot texnologiyalari va kommunikatsiyalarini rivojlantirish vazirligi muhammad al-xorazmiy nomidagi toshkent axborot texnologiyalari universiteti fakultet
|
bet | 31/32 | Sana | 08.07.2024 | Hajmi | 2,32 Mb. | | #267039 |
Bog'liq Miraxmedov Xusanboy BMIILOVA
Dastur kodi
Mijozdan buyurtma olishni amalga oshiruvchi kod fragmenti.
import cors from 'cors';
import path from 'path';
import morgan from 'morgan';
import expressFileUpload from 'express-fileupload';
import express, { Express, Router } from 'express';
import { express as ExpressUseragent } from 'express-useragent';
import errorHandler from './modules/shared/middlewares/errorHandler';
var cookieParser = require('cookie-parser');
class App {
public app: Express;
constructor(router: Router) {
this.app = express();
this.initializeMiddlewares();
this.initializeRoutes(router);
this.initializeErrorHandling();
}
public get getServer() {
return this.app;
}
private initializeMiddlewares() {
this.app.use(cookieParser('JOHNY_SECRET_KEY'));
this.app.use(
cors({
origin: [
'http://localhost:3000',
'http://localhost:3001',
'https://admin.lunasushi.lv',
'https://lunasushi.lv',
'https://samarkand.lv',
'https://admin.samarkand.lv',
],
methods: ['GET', 'POST', 'PUT', 'DELETE'],
credentials: true,
})
);
this.app.use(express.json());
this.app.use(ExpressUseragent());
this.app.use(express.urlencoded({ extended: true }));
this.app.use(expressFileUpload({ useTempFiles: true }));
this.app.use(
'/api/images',
express.static(
path.join(__dirname, '..', 'public', 'uploads', 'images')
)
);
this.app.use(morgan('tiny'));
}
private initializeRoutes(router: Router) {
this.app.use('/api', router);
}
private initializeErrorHandling() {
this.app.use(errorHandler);
}
}
export default App;
Foydalanuvchi tomonidan yuborilgan so‘rovlarni qabul qilib olishni amalga oshiruvchi kod fragmenti.
import { Router } from 'express';
import AuthRoute from './modules/auth/auth.route';
import MenuRoute from './modules/menu/menu.route';
import ProductRoute from './modules/products/product.route';
import StatusRoute from './modules/status/status.route';
import DistrictsRoute from './modules/districts/districts.route';
import OrdersRoute from './modules/orders/orders.route';
const router = Router();
const authRoute = new AuthRoute();
const menuRoute = new MenuRoute();
const productRoute = new ProductRoute();
const statusRoute = new StatusRoute();
const districtsRoute = new DistrictsRoute();
const ordersRoute = new OrdersRoute();
router.use('/', authRoute.router);
router.use('/', menuRoute.router);
router.use('/', productRoute.router);
router.use('/', statusRoute.router);
router.use('/', districtsRoute.router);
router.use('/', ordersRoute.router);
export default router;
|
|
Bosh sahifa
Aloqalar
Bosh sahifa
O‘zbekiston respublikasi axborot texnologiyalari va kommunikatsiyalarini rivojlantirish vazirligi muhammad al-xorazmiy nomidagi toshkent axborot texnologiyalari universiteti fakultet
|