דילוג לתוכן
  • חוקי הפורום
  • פופולרי
  • לא נפתר
  • משתמשים
  • חיפוש גוגל בפורום
  • צור קשר
עיצובים
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • ברירת מחדל (ללא עיצוב (ברירת מחדל))
  • ללא עיצוב (ברירת מחדל)
כיווץ
מתמחים טופ
  1. דף הבית
  2. מחשבים וטכנולוגיה
  3. רשתות
  4. פיתוח ועיצוב אתרים
  5. Full Stack
  6. צד שרת
  7. NodeJS
  8. עזרה הדדית - NodeJS
  9. עזרה | פיצול קובץ למבנה נכון (route, controller ועוד)

עזרה | פיצול קובץ למבנה נכון (route, controller ועוד)

מתוזמן נעוץ נעול הועבר עזרה הדדית - NodeJS
12 פוסטים 2 כותבים 29 צפיות 1 עוקבים
  • מהישן לחדש
  • מהחדש לישן
  • הכי הרבה הצבעות
תגובה
  • תגובה כנושא
התחברו כדי לפרסם תגובה
נושא זה נמחק. רק משתמשים עם הרשאות מתאימות יוכלו לצפות בו.
  • ע מנותק
    ע מנותק
    עידו300
    כתב נערך לאחרונה על ידי עידו300
    #1

    יש לי קובץ גדול ואני אשמח לדוגמא איך נכון לחלק אותו בין החלקים הנ"ל.
    תודה.

    import express, { json } from 'express';
    import { YemotRouter } from 'yemot-router2';
    import { fileURLToPath } from 'url';
    import process from 'process';
    export const app = express();
    import { streets, regions, citys} from './src/utils/streets_data.js';
    import { *** } from './src/utils/utils_func.js';
    import https from 'https';
    import { rejects } from 'assert';
    
    export const router = YemotRouter({
        printLog: true,
        uncaughtErrorHandler: (error, call) => {
            console.log(`Uncaught error in ${call.req.path} from ${call.phone}. error stack: ${error.stack}`);
            // do something with the error - like send email to developer, print details log, etc.
            return call.id_list_message([{ type: 'text', data: 'אירעה שגיאה' }]); // play nice error message to the caller
        }
    });
    
    router.events.on('call_hangup', (call) => {
        console.log(`[addAd.js] call ${call.callId} was hangup`);
    });
    
    router.events.on('call_continue', (call) => {
        console.log(`[addAd.js] call ${call.callId} was continue`);
    });
    
    router.events.on('new_call', (call) => {
        console.log(`[addAd.js] new call ${call.callId} from ${call.phone}`);
    });
    
    /** @param {import('yemot-router2').Call} call */
    async function callHandler (call) {
    
    לוגיקה של יצירת ואישור מודעה
    /*************************************************************************************** */
    //                        הוספה למאגר מידע
    
    console.log("מכין בקשה");
    const params = new URLSearchParams({
          ****});
    const url =*******;
    
    console.log("שולח בקשה");
    let response = await sendRequest(call, url, "אירעה שגיאה בעת שמירת המודעה");
        console.log('Response:', response);
    
        if (response.status === "success") {
            call.id_list_message([{ type: "text", data: response.message }]);
        }
    }
    
    
    /*************************************************************************************** */
    
    
    router.get('/', callHandler);
    
    // this must if you want to use post requests (api_url_post=yes)
    app.use(express.urlencoded({ extended: true }));
    
    app.use('/', router);
    
    console.log('Node starting...');
    const port = 3000;
    //const isMain = process.argv[1] ===
        app.listen(port, () => {
            console.log(`example yemot-router2 running on port ${port}`);
        });
    
    תגובה 1 תגובה אחרונה
    0
    • צדיק תמיםצ מנותק
      צדיק תמיםצ מנותק
      צדיק תמים
      מדריכים
      כתב נערך לאחרונה על ידי צדיק תמים
      #2

      controller.js (אם יש הרבה מומלץ לפצל לקבצים לפי תחום וכדומה)

      /** @param {import('yemot-router2').Call} call */
      async function callHandler (call) {
       
      לוגיקה של יצירת ואישור מודעה
      /*************************************************************************************** */
      //                        הוספה למאגר מידע
       
      console.log("מכין בקשה");
      const params = new URLSearchParams({
            ****});
      const url =*******;
       
      console.log("שולח בקשה");
      let response = await sendRequest(call, url, "אירעה שגיאה בעת שמירת המודעה");
          console.log('Response:', response);
       
          if (response.status === "success") {
              call.id_list_message([{ type: "text", data: response.message }]);
          }
      } 
      

      router.js

      export const router = YemotRouter({
          printLog: true,
          uncaughtErrorHandler: (error, call) => {
              console.log(`Uncaught error in ${call.req.path} from ${call.phone}. error stack: ${error.stack}`);
              // do something with the error - like send email to developer, print details log, etc.
              return call.id_list_message([{ type: 'text', data: 'אירעה שגיאה' }]); // play nice error message to the caller
          }
      });
       
      router.events.on('call_hangup', (call) => {
          console.log(`[addAd.js] call ${call.callId} was hangup`);
      });
       
      router.events.on('call_continue', (call) => {
          console.log(`[addAd.js] call ${call.callId} was continue`);
      });
       
      router.events.on('new_call', (call) => {
          console.log(`[addAd.js] new call ${call.callId} from ${call.phone}`);
      });
      
      router.get('/', callHandler);
      

      app.js

      // this must if you want to use post requests (api_url_post=yes)
      app.use(express.urlencoded({ extended: true }));
      
      app.use('/', router);
      
      console.log('Node starting...');
      const port = 3000;
         app.listen(port, () => {
             console.log(`example yemot-router2 running on port ${port}`);
         });
      

      רוצה לזכור קריאת שמע בזמן? לחץ כאן! || אתר שכולו מדריכים

      ע 2 תגובות תגובה אחרונה
      0
      • צדיק תמיםצ צדיק תמים

        controller.js (אם יש הרבה מומלץ לפצל לקבצים לפי תחום וכדומה)

        /** @param {import('yemot-router2').Call} call */
        async function callHandler (call) {
         
        לוגיקה של יצירת ואישור מודעה
        /*************************************************************************************** */
        //                        הוספה למאגר מידע
         
        console.log("מכין בקשה");
        const params = new URLSearchParams({
              ****});
        const url =*******;
         
        console.log("שולח בקשה");
        let response = await sendRequest(call, url, "אירעה שגיאה בעת שמירת המודעה");
            console.log('Response:', response);
         
            if (response.status === "success") {
                call.id_list_message([{ type: "text", data: response.message }]);
            }
        } 
        

        router.js

        export const router = YemotRouter({
            printLog: true,
            uncaughtErrorHandler: (error, call) => {
                console.log(`Uncaught error in ${call.req.path} from ${call.phone}. error stack: ${error.stack}`);
                // do something with the error - like send email to developer, print details log, etc.
                return call.id_list_message([{ type: 'text', data: 'אירעה שגיאה' }]); // play nice error message to the caller
            }
        });
         
        router.events.on('call_hangup', (call) => {
            console.log(`[addAd.js] call ${call.callId} was hangup`);
        });
         
        router.events.on('call_continue', (call) => {
            console.log(`[addAd.js] call ${call.callId} was continue`);
        });
         
        router.events.on('new_call', (call) => {
            console.log(`[addAd.js] new call ${call.callId} from ${call.phone}`);
        });
        
        router.get('/', callHandler);
        

        app.js

        // this must if you want to use post requests (api_url_post=yes)
        app.use(express.urlencoded({ extended: true }));
        
        app.use('/', router);
        
        console.log('Node starting...');
        const port = 3000;
           app.listen(port, () => {
               console.log(`example yemot-router2 running on port ${port}`);
           });
        
        ע מנותק
        ע מנותק
        עידו300
        כתב נערך לאחרונה על ידי
        #3

        @צדיק-תמים תודה
        אבל יש לי 4 קבצים, אז לעשות תיקיה מכל סוג ואז בכל תיקיה addAdRoute/controller
        והapp הוא מרכזי לכולם? מה אמור להיות בו?

        צדיק תמיםצ תגובה 1 תגובה אחרונה
        0
        • ע עידו300

          @צדיק-תמים תודה
          אבל יש לי 4 קבצים, אז לעשות תיקיה מכל סוג ואז בכל תיקיה addAdRoute/controller
          והapp הוא מרכזי לכולם? מה אמור להיות בו?

          צדיק תמיםצ מנותק
          צדיק תמיםצ מנותק
          צדיק תמים
          מדריכים
          כתב נערך לאחרונה על ידי
          #4

          @עידו300 למה 4 קבצים?
          נתתי פה דוגמה לעץ קבצים

          רוצה לזכור קריאת שמע בזמן? לחץ כאן! || אתר שכולו מדריכים

          ע תגובה 1 תגובה אחרונה
          0
          • צדיק תמיםצ צדיק תמים

            @עידו300 למה 4 קבצים?
            נתתי פה דוגמה לעץ קבצים

            ע מנותק
            ע מנותק
            עידו300
            כתב נערך לאחרונה על ידי
            #5

            @צדיק-תמים כי יש לי ככה:

            1. קובץ שאחראי על הוספת מודעות חדשות.
            2. קובץ שאחראי על ניהול המודעות.
            3. קובץ שאחראי על מציאת התאמה למודעות/רישום להתראות.
            4. קובץ שאחראי על ניהול ההתראות של מחפש הדירה.

            אני לא יכול לשים את כל זה בקובץ אחד, גם ככה זה בלאגן.

            וזה בלי הקובץ של הפונקציות הכלליות והקובץ של המידע

            צדיק תמיםצ תגובה 1 תגובה אחרונה
            0
            • ע עידו300

              @צדיק-תמים כי יש לי ככה:

              1. קובץ שאחראי על הוספת מודעות חדשות.
              2. קובץ שאחראי על ניהול המודעות.
              3. קובץ שאחראי על מציאת התאמה למודעות/רישום להתראות.
              4. קובץ שאחראי על ניהול ההתראות של מחפש הדירה.

              אני לא יכול לשים את כל זה בקובץ אחד, גם ככה זה בלאגן.

              וזה בלי הקובץ של הפונקציות הכלליות והקובץ של המידע

              צדיק תמיםצ מנותק
              צדיק תמיםצ מנותק
              צדיק תמים
              מדריכים
              כתב נערך לאחרונה על ידי צדיק תמים
              #6

              @עידו300 לא בטוח שזה לא מתאים לקובץ אחד, בכל מקרה אין בעיה, תעשה תקיית controllers ובה כמה קבצים שתרצה

              @עידו300 כתב בעזרה | פיצול קובץ למבנה נכון (route, controller ועוד):

              והapp הוא מרכזי לכולם? מה אמור להיות בו?

              הוא הקובץ הראשי, אותו בעצם אתה מריץ כדי להריץ את האפליקציה, הוא אמור להכיל דברים גלובליים ממש כמו אתחול אקספרס, הגדרת מידלוורים גלובליים, התחברות לדאטהבייס, וכמובן האזנה על פורט

              רוצה לזכור קריאת שמע בזמן? לחץ כאן! || אתר שכולו מדריכים

              ע תגובה 1 תגובה אחרונה
              1
              • צדיק תמיםצ צדיק תמים

                @עידו300 לא בטוח שזה לא מתאים לקובץ אחד, בכל מקרה אין בעיה, תעשה תקיית controllers ובה כמה קבצים שתרצה

                @עידו300 כתב בעזרה | פיצול קובץ למבנה נכון (route, controller ועוד):

                והapp הוא מרכזי לכולם? מה אמור להיות בו?

                הוא הקובץ הראשי, אותו בעצם אתה מריץ כדי להריץ את האפליקציה, הוא אמור להכיל דברים גלובליים ממש כמו אתחול אקספרס, הגדרת מידלוורים גלובליים, התחברות לדאטהבייס, וכמובן האזנה על פורט

                ע מנותק
                ע מנותק
                עידו300
                כתב נערך לאחרונה על ידי
                #7

                @צדיק-תמים כל הimport בקונטרולר נכון?

                צדיק תמיםצ תגובה 1 תגובה אחרונה
                0
                • ע עידו300

                  @צדיק-תמים כל הimport בקונטרולר נכון?

                  צדיק תמיםצ מנותק
                  צדיק תמיםצ מנותק
                  צדיק תמים
                  מדריכים
                  כתב נערך לאחרונה על ידי
                  #8

                  @עידו300 import של מה? כל דבר מייבאים איפה שמשתמשים בו

                  רוצה לזכור קריאת שמע בזמן? לחץ כאן! || אתר שכולו מדריכים

                  תגובה 1 תגובה אחרונה
                  1
                  • צדיק תמיםצ צדיק תמים

                    controller.js (אם יש הרבה מומלץ לפצל לקבצים לפי תחום וכדומה)

                    /** @param {import('yemot-router2').Call} call */
                    async function callHandler (call) {
                     
                    לוגיקה של יצירת ואישור מודעה
                    /*************************************************************************************** */
                    //                        הוספה למאגר מידע
                     
                    console.log("מכין בקשה");
                    const params = new URLSearchParams({
                          ****});
                    const url =*******;
                     
                    console.log("שולח בקשה");
                    let response = await sendRequest(call, url, "אירעה שגיאה בעת שמירת המודעה");
                        console.log('Response:', response);
                     
                        if (response.status === "success") {
                            call.id_list_message([{ type: "text", data: response.message }]);
                        }
                    } 
                    

                    router.js

                    export const router = YemotRouter({
                        printLog: true,
                        uncaughtErrorHandler: (error, call) => {
                            console.log(`Uncaught error in ${call.req.path} from ${call.phone}. error stack: ${error.stack}`);
                            // do something with the error - like send email to developer, print details log, etc.
                            return call.id_list_message([{ type: 'text', data: 'אירעה שגיאה' }]); // play nice error message to the caller
                        }
                    });
                     
                    router.events.on('call_hangup', (call) => {
                        console.log(`[addAd.js] call ${call.callId} was hangup`);
                    });
                     
                    router.events.on('call_continue', (call) => {
                        console.log(`[addAd.js] call ${call.callId} was continue`);
                    });
                     
                    router.events.on('new_call', (call) => {
                        console.log(`[addAd.js] new call ${call.callId} from ${call.phone}`);
                    });
                    
                    router.get('/', callHandler);
                    

                    app.js

                    // this must if you want to use post requests (api_url_post=yes)
                    app.use(express.urlencoded({ extended: true }));
                    
                    app.use('/', router);
                    
                    console.log('Node starting...');
                    const port = 3000;
                       app.listen(port, () => {
                           console.log(`example yemot-router2 running on port ${port}`);
                       });
                    
                    ע מנותק
                    ע מנותק
                    עידו300
                    כתב נערך לאחרונה על ידי
                    #9

                    @צדיק-תמים כתב בעזרה | פיצול קובץ למבנה נכון (route, controller ועוד):

                    controller.js (אם יש הרבה מומלץ לפצל לקבצים לפי תחום וכדומה)

                    /** @param {import('yemot-router2').Call} call */
                    async function callHandler (call) {
                     
                    לוגיקה של יצירת ואישור מודעה
                    /*************************************************************************************** */
                    //                        הוספה למאגר מידע
                     
                    console.log("מכין בקשה");
                    const params = new URLSearchParams({
                          ****});
                    const url =*******;
                     
                    console.log("שולח בקשה");
                    let response = await sendRequest(call, url, "אירעה שגיאה בעת שמירת המודעה");
                        console.log('Response:', response);
                     
                        if (response.status === "success") {
                            call.id_list_message([{ type: "text", data: response.message }]);
                        }
                    } 
                    

                    כאן בקונטרולר צריך לייבא את הספריה של ימות המשיח, לא?

                    router.js

                    export const router = YemotRouter({
                        printLog: true,
                        uncaughtErrorHandler: (error, call) => {
                            console.log(`Uncaught error in ${call.req.path} from ${call.phone}. error stack: ${error.stack}`);
                            // do something with the error - like send email to developer, print details log, etc.
                            return call.id_list_message([{ type: 'text', data: 'אירעה שגיאה' }]); // play nice error message to the caller
                        }
                    });
                     
                    router.events.on('call_hangup', (call) => {
                        console.log(`[addAd.js] call ${call.callId} was hangup`);
                    });
                     
                    router.events.on('call_continue', (call) => {
                        console.log(`[addAd.js] call ${call.callId} was continue`);
                    });
                     
                    router.events.on('new_call', (call) => {
                        console.log(`[addAd.js] new call ${call.callId} from ${call.phone}`);
                    });
                    
                    router.get('/', callHandler);
                    

                    גם כאן בראוט

                    app.js

                    // this must if you want to use post requests (api_url_post=yes)
                    app.use(express.urlencoded({ extended: true }));
                    
                    app.use('/', router);
                    
                    console.log('Node starting...');
                    const port = 3000;
                       app.listen(port, () => {
                           console.log(`example yemot-router2 running on port ${port}`);
                       });
                    

                    וכאן את של האקספרס

                    צדיק תמיםצ תגובה 1 תגובה אחרונה
                    0
                    • ע עידו300

                      @צדיק-תמים כתב בעזרה | פיצול קובץ למבנה נכון (route, controller ועוד):

                      controller.js (אם יש הרבה מומלץ לפצל לקבצים לפי תחום וכדומה)

                      /** @param {import('yemot-router2').Call} call */
                      async function callHandler (call) {
                       
                      לוגיקה של יצירת ואישור מודעה
                      /*************************************************************************************** */
                      //                        הוספה למאגר מידע
                       
                      console.log("מכין בקשה");
                      const params = new URLSearchParams({
                            ****});
                      const url =*******;
                       
                      console.log("שולח בקשה");
                      let response = await sendRequest(call, url, "אירעה שגיאה בעת שמירת המודעה");
                          console.log('Response:', response);
                       
                          if (response.status === "success") {
                              call.id_list_message([{ type: "text", data: response.message }]);
                          }
                      } 
                      

                      כאן בקונטרולר צריך לייבא את הספריה של ימות המשיח, לא?

                      router.js

                      export const router = YemotRouter({
                          printLog: true,
                          uncaughtErrorHandler: (error, call) => {
                              console.log(`Uncaught error in ${call.req.path} from ${call.phone}. error stack: ${error.stack}`);
                              // do something with the error - like send email to developer, print details log, etc.
                              return call.id_list_message([{ type: 'text', data: 'אירעה שגיאה' }]); // play nice error message to the caller
                          }
                      });
                       
                      router.events.on('call_hangup', (call) => {
                          console.log(`[addAd.js] call ${call.callId} was hangup`);
                      });
                       
                      router.events.on('call_continue', (call) => {
                          console.log(`[addAd.js] call ${call.callId} was continue`);
                      });
                       
                      router.events.on('new_call', (call) => {
                          console.log(`[addAd.js] new call ${call.callId} from ${call.phone}`);
                      });
                      
                      router.get('/', callHandler);
                      

                      גם כאן בראוט

                      app.js

                      // this must if you want to use post requests (api_url_post=yes)
                      app.use(express.urlencoded({ extended: true }));
                      
                      app.use('/', router);
                      
                      console.log('Node starting...');
                      const port = 3000;
                         app.listen(port, () => {
                             console.log(`example yemot-router2 running on port ${port}`);
                         });
                      

                      וכאן את של האקספרס

                      צדיק תמיםצ מנותק
                      צדיק תמיםצ מנותק
                      צדיק תמים
                      מדריכים
                      כתב נערך לאחרונה על ידי
                      #10

                      @עידו300 כמובן, לא טרחתי כל אחד לציין מה לייבא בו

                      רוצה לזכור קריאת שמע בזמן? לחץ כאן! || אתר שכולו מדריכים

                      ע תגובה 1 תגובה אחרונה
                      1
                      • צדיק תמיםצ צדיק תמים

                        @עידו300 כמובן, לא טרחתי כל אחד לציין מה לייבא בו

                        ע מנותק
                        ע מנותק
                        עידו300
                        כתב נערך לאחרונה על ידי
                        #11

                        @צדיק-תמים לcallHandler צריך לעשות export וליבא אותו בראוט?

                        צדיק תמיםצ תגובה 1 תגובה אחרונה
                        0
                        • ע עידו300

                          @צדיק-תמים לcallHandler צריך לעשות export וליבא אותו בראוט?

                          צדיק תמיםצ מנותק
                          צדיק תמיםצ מנותק
                          צדיק תמים
                          מדריכים
                          כתב נערך לאחרונה על ידי
                          #12

                          @עידו300 בראוטר
                          כן

                          רוצה לזכור קריאת שמע בזמן? לחץ כאן! || אתר שכולו מדריכים

                          תגובה 1 תגובה אחרונה
                          0

                          • התחברות

                          • אין לך חשבון עדיין? הרשמה

                          • התחברו או הירשמו כדי לחפש.
                          • פוסט ראשון
                            פוסט אחרון
                          0
                          • חוקי הפורום
                          • פופולרי
                          • לא נפתר
                          • משתמשים
                          • חיפוש גוגל בפורום
                          • צור קשר