I recently switched from an Express web application to a BrowserSync application for nodejs. Using Express, if I wanted to set a cookie, my configuration would look something like this:
var express = require('express'); var session = require('express-session'); var finalhandler = require('finalhandler'); var serveStatic = require('serve-static'), serve = serveStatic(__dirname); var app = express(); app.use(session({
My team started using BrowserSync (via the gulp task), and my configuration so far looks something like this:
var gulp = require('gulp'), browserSync = require('browser-sync'), gulpLoadPlugins = require('gulp-load-plugins'), plugins = gulpLoadPlugins(); gulp.task('browser-sync', function() { browserSync({ server: { baseDir: "./", middleware: [ function(req, res, next) { res.cookie('myCookie', 'my cookie value'); next(); } ] }, port: 8080 }); });
However, the res
object does not have a method called cookie. Is there something similar to session middleware for Expressjs that will work as BrowserSync middleware? Is there any other way to set cookies on a BrowserSync server?
source share