coffeescript

PassportJS redirect loop

爷,独闯天下 提交于 2019-12-13 14:06:32
问题 Below is the code I have restify = require("restify") passport = require("passport") GoogleStrategy = require("passport-google").Strategy jsonContentType = (req, res, next) -> res.setHeader("content-type", "application/json") next(req, res, next) server = restify.createServer( name: "Sparked API" ) passport.use(new GoogleStrategy({ returnURL: "http://localhost:8080/auth/google/return" realm: "http://localhost:8080/" }, (id, profile, done) -> done() )) server.use(jsonContentType) server.get("/

Node.js: Read params passed in the URL

末鹿安然 提交于 2019-12-13 13:21:44
问题 In rails I do a POST request to my server: response = Typhoeus::Request.post("http://url.localtunnel.com/request?from=ola&to=ole") result = JSON.parse(response.body) In the Node.js app, I want to read From and To : app.post '/request', (req,res) -> console.log "I have received a request, sweet!!" sys.log req.params.from #sys.log "From: " + req.from + ", To: " + req.to + ", Id: " + req.id How do I do it? Thanks 回答1: The answer is: Checks query string params (req.query), ex: ?id=12 回答2:

How do I call a JS callback when a file upload completes?

好久不见. 提交于 2019-12-13 13:04:25
问题 I'm creating frontend upload for an app with appengine backend. What I want to make is a file upload solution, and I dont want to be using plupload or those kinds of ready-made solutions. I basically submitted the images to an iframe and then put a cover while it is uploading. Then after it finishes I performed an ajax call to get the image ids for the next view to be rendered. However, the render is always called before the upload is completed, thus I'm not getting any image ids from the

is there a coffeescript auto compile / file watcher for windows?

放肆的年华 提交于 2019-12-13 11:57:08
问题 I'd like to play around with integrating coffeescript into my dev process. But as I see it, I'll have to make a bat file that iterates a set of coffee files and spits out js files. Every time I write a bat file, useful as they may be, I ask myself: is there a better way? Which makes me wonder: is there an app of some sort for Windows that will watch a directory or a file and spit out one/many js files when a coffee file is saved? I'm thinking of building one but don't want to reinvent the

Selenium-Webdriver w/ Chai as Promised and Mocha failing to wait

自古美人都是妖i 提交于 2019-12-13 07:48:07
问题 I've got a simple coffeescript test w/ Selenium-Webdriver using Chai-as-Promised and Mocha which is supposed to test a web page that I have that uses an AJAX call to do authentication once a login button is pressed: selenium = require 'selenium-webdriver' chai = require 'chai' chai.use require 'chai-as-promised' expect = chai.expect before -> @timeout 10000 @driver = new selenium.Builder() .withCapabilities(selenium.Capabilities.chrome()) .build() @driver.getWindowHandle() after -> @driver

Translating jQuery to Coffeescript

邮差的信 提交于 2019-12-13 06:49:54
问题 I posted a confusing question before. Long story short, I have a bit of jQuery working close to the way I want, but I cannot for the life of me get it to work in CoffeeScript. When I try it different ways in CS the "on search" event triggers as soon as the page is loaded. I can't get it to just attach to the dataTable as I do in jQuery. I'm sure it's something simple and dumb. Here's the code: $(document).ready(function() { $('#customers').dataTable( { "sPaginationType": "bootstrap",

Streaming Results and res.render nodejs

假装没事ソ 提交于 2019-12-13 05:55:43
问题 I am using express and mysql-native with nodejs. With the mysql-native I stream results from the db row by row like this (in coffee): exports.getUser = (username,callback) -> query = mysql.query "select * from users where username = #{username}" query.on "row", (row)-> callback row (obviously I would use prepared statements this is an example) This sort of method won't work with res.render because you cannot be calling the res.render multiple times every time you get a new row database

In Javascript/Coffeescript how can I mock out a module's public variable in a test?

℡╲_俬逩灬. 提交于 2019-12-13 05:44:39
问题 I just learned about the module pattern. I've written some code that's gotten sufficiently complex that I want to test a feature. The problem is, I can't figure out how to mock out a value. What follows is coffeescript, but I'll put the generated javascript below so I can get more help. Here's my test that attempts to mock out a field named state , but it always prints "undefined": root = exports ? this root.test3 = (-> root.test2.state = "abc" root.test2.doSomething() return {} )() And here

submiting form on div click with js

孤人 提交于 2019-12-13 05:38:53
问题 I have a div element and I want that when I click on it i submit a form which is hidden. div code <div class="a15 training-exercise"> some text <form accept-charset="UTF-8" action="/trainings/1/training_exercises/5" data-remote="true" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="_method" type="hidden" value="put"></div> <input id="training_exercise_done" name="training_exercise[done]" type="text" value="false"> <input

Karma and CoffeScript and Code Coverage

筅森魡賤 提交于 2019-12-13 04:55:46
问题 I think something may be wrong with the Karma CoffeeScript code coverage preprocessor. Or I'm not sure what I'm doing wrong! So I come to you StackOverflow. Basically I'm trying to setup my karma test suite to give me code coverage in an lcov format so I can ship that off to CodeClimate. I had it so my test suite (used to) work, but now I can't seem to get anything from it except errors. My project is a Rails project and the files are setup to be preprocessed by the asset pipe (ie. name.js