ها باید تنظیم شوند session هایی که در property در مورد

پرسیده شده
فعالیت 1439 روز پیش
دیده شده 887 بار
0

با سلام و عرض وقت بخیر و خسته نباشید خدمت استاد

1) سوالم این است که با توجه به متن زیر 

secure = true
استفاده کنه؟Httpsزمانی میتونه باشه که سایتمون از پروتکل

cookie.secure

Specifies the boolean value for the Secure Set-Cookie attribute. When truthy, the Secure attribute is set, otherwise it is not. By default, the Secure attribute is not set.

Note be careful when setting this to true, as compliant clients will not send the cookie back to the server in the future if the browser does not have an HTTPS connection.

Please note that secure: true is a recommended option. However, it requires an https-enabled website, i.e., HTTPS is necessary for secure cookies. If secure is set, and you access your site over HTTP, the cookie will not be set. If you have your node.js behind a proxy and are using secure: true, you need to set "trust proxy" in express:

 

var app = express()

app.set('trust proxy', 1) // trust first proxy

app.use(session({

  secret: 'keyboard cat',

  resave: false,

  saveUninitialized: true,

  cookie: { secure: true }

}))

For using secure cookies in production, but allowing for testing in development, the following is an example of enabling this setup based on NODE_ENV in express:

 

var app = express()

var sess = {

  secret: 'keyboard cat',

  cookie: {}

}

 

if (app.get('env') === 'production') {

  app.set('trust proxy', 1) // trust first proxy

  sess.cookie.secure = true // serve secure cookies

}

 

app.use(session(sess))

The cookie.secure option can also be set to the special value 'auto' to have this setting automatically match the determined security of the connection. Be careful when using this setting if the site is available both as HTTP and HTTPS, as once the cookie is set on HTTPS, it will no longer be visible over HTTP. This is useful when the Express "trust proxy" setting is properly setup to simplify development vs production configuration.

 

بود؟Http و اگر پروتکل

و انتقادی هم دارم از روش تدریس که چرا داکیونت هر متدی رو توضیح نمیدید شاید کسی زبانش خوب نباشه واقعا خیلی مهمه که بفهمیم که هر متدی چه کاری انجام میده 
و انتقاد بعدی هم اینه که چرا پروژه محور جلو نمیرید این مبحث رو 

 

فایل پیوست

مصطفی قدیم پور
مصطفی قدیم پور

5 خرداد 99

1
حذف شده

گزینه resave یعنی حتی اگر کاربر تغییری در سشن نداشته باشه، تمام سشن باید در storage ذخیره بشه.

گزینه saveUninitialized یعنی سشن ایجاد شده اما هنوز در اون دیتایی قرار نگرفته و این گزینه مشخص میکنه این سشن آیا باید در storage ذخیره بشه یا نه.

گزینه set proxy هم برای حالتی هست که کل برنامه در پشت یک proxy مثل nginx قرار میگیره و اونجا برای اینکه مشکلی از لحاظ تنظیم کردن header ها وجود نداشته باشه و کوکی به درستی کار کنه .

فایل پیوست

کیوان علی محمدی

توسط

کیوان علی محمدی

6 خرداد 99

2
حذف شده

سلام خدمت شما. 

1 - برای secure کردن حتما باید روی https باشه در غیر این صورت session ها به درستی کار نمیکنن.

2 - خب واقعا در هر آموزشی نمیشه تمام متدهای اون فریمورک رو دونه به دونه توضیح داد هم خسته کننده میشه و هم وقت آموزش بسیار زیاد میشه و به یادگیری هم ضربه میزنه. اگر قصد دارید برنامه نویس بشید حتما روی زبان انگلیسی سرمایه گذاری کنید.

3 - دوره فقط برای معرفی فریمورک express هست و در سرفصل بعدی به صورت پروژه به این موضوع پرداخته شده.این مورد فقط برای یادگیری بهتر دانشجویان پیاده سازی شده.

فایل پیوست

کیوان علی محمدی

توسط

کیوان علی محمدی

5 خرداد 99

0
حذف شده

با سلام و عرض وقت بخیر خدمت استاد عزیز

بکار گرفته شده بود که واقعا هرsession ممنونم از پاسخ شما . من منظورم همه ی متد ها نبود همون هایی که توی 

کدومشون برای چه منظوری هستند

مثلا:

var app = express()
app.set('trust proxy', 1) // trust first proxy
app.use(session({
  secret: 'keyboard cat',
  resave: false,
  saveUninitialized: true,
  cookie: { secure: true }
}))

property resave & saveUninitialized

why set proxy?
با سپاس فراوان از شما

 

 

فایل پیوست

مصطفی قدیم پور

توسط

مصطفی قدیم پور

5 خرداد 99