restify

Redirecting client with NodeJS and Restify

泄露秘密 提交于 2019-12-04 16:51:20
问题 I'm building a REST backend for an SPA with NodeJS, Restify and PassportJS for authentication. Everything's working except the last step, which is redirecting the client from the backends /login/facebook/callback to the home page of the application. I've searched online and found lots of answers for ExpressJS but nothing useful for Node-Restify yet. I've managed to pick up a few snippets of code and this is what I'm attempting at the moment: app.get('/api/v1/login/facebook/cb', passport

What's the best practice for MongoDB connections on Node.js?

假如想象 提交于 2019-12-04 08:01:20
问题 This is something that is a bit unclear to me (I'm just getting started with Node and Mongo), and it really concerns me because of server performance and strain (which I guess is another question, but I'll get to that at the end of the post). So, assuming I'm writing an API with Node.js and Restify, where each API endpoint corresponds to a function, should I: a) open the db connection and store it in a global var, and then just use that in every function? Example: // requires and so on leave

Using everyauth with restify

非 Y 不嫁゛ 提交于 2019-12-03 16:30:19
I'm trying to use everyauth to handle authentication for a rest api created with restify. But can't find a starting point. I'd expect to be doing something like: var restify = require('restify'); var everyauth = require('everyauth'); var server = restify.createServer(); server.use(everyauth.middleware()); but restify does not accept the everyauth middleware. How do I go about setting up restify and everyauth? The issue you are having is restify does not and current will not have a middleware layer. The below is from the author of restify I've thought about this quite a bit, and the thing that

location object expected, location array not in correct format

左心房为你撑大大i 提交于 2019-12-03 15:13:22
I have spent doing such a straight forward thing. I just want to do a CRUD operation on a user model using nodejs, mongoose, restify stack. My mongo instance is on mongolab. The user should contain a "loc" field . User schema is as follows : var mongoose = require('mongoose') var Schema = mongoose.Schema; var userSchema = new Schema( { email_id : { type: String, unique: true }, password: { type: String}, first_name: String, last_name: String, age: String, phone_number: String, profile_picture: String, loc: { type: {}, coordinates: [Number] } }); userSchema.index({loc:'2d'}); var User =

Serving static files with restify

喜夏-厌秋 提交于 2019-12-03 14:35:19
问题 I am learning to use Node.js. Currently, I have a folder structure that looks like the following: index.html server.js client index.html subs index.html page.html res css style.css img profile.png js page.js jquery.min.js server.js is my webserver code. I run this from a command-line using node server.js . The contents of that file are: var restify = require('restify'); var server = restify.createServer({ name: 'Test App', version: '1.0.0' }); server.use(restify.acceptParser(server.acceptable

Redirecting client with NodeJS and Restify

给你一囗甜甜゛ 提交于 2019-12-03 10:43:46
I'm building a REST backend for an SPA with NodeJS, Restify and PassportJS for authentication. Everything's working except the last step, which is redirecting the client from the backends /login/facebook/callback to the home page of the application. I've searched online and found lots of answers for ExpressJS but nothing useful for Node-Restify yet. I've managed to pick up a few snippets of code and this is what I'm attempting at the moment: app.get('/api/v1/login/facebook/cb', passport.authenticate('facebook', { scope: 'email' }), function(req, res) { req.session.user = req.user._id; res

restify 2.6.1 how to disable body parser for specific request

不问归期 提交于 2019-12-03 08:05:51
I am pretty new to node.js services and I am facing a problem with multipart/form-data content type. I need a way to disable body parser functionality for specific request. I am using restify 2.6.1. Below are some snippet of the configuration. My setup is: App.js : server.use(restify.authorizationParser()); server.use(restify.dateParser()); server.use(restify.queryParser()); server.use(restify.jsonp()); server.use(restify.bodyParser()); server.use(restifyValidator); server.use(restify.gzipResponse()); server.use(passport.initialize()); server.use(restify.conditionalRequest()); Route.js : app

serving static files with restify (node.js)

六月ゝ 毕业季﹏ 提交于 2019-12-03 06:46:11
问题 I have the following code: app.js [...] server.get(/\/docs\/public\/?.*/, restify.serveStatic({ directory: './public' })); server.listen(1337, function() { console.log('%s listening at %s', server.name, server.url); }); And I have the following file structure app.js public/ index.html So I try browsing: http://localhost:1337/docs/public/index.html and I get { code: "ResourceNotFound", message: "/docs/public/index.html" } I tried with several variations, but none of them seemed to work. I'm

Serving static files with RESTIFY

女生的网名这么多〃 提交于 2019-12-03 04:20:47
I am learning to use Node.js. Currently, I have a folder structure that looks like the following: index.html server.js client index.html subs index.html page.html res css style.css img profile.png js page.js jquery.min.js server.js is my webserver code. I run this from a command-line using node server.js . The contents of that file are: var restify = require('restify'); var server = restify.createServer({ name: 'Test App', version: '1.0.0' }); server.use(restify.acceptParser(server.acceptable)); server.use(restify.queryParser()); server.use(restify.bodyParser()); server.get('/echo/:name',

serving static files with restify (node.js)

点点圈 提交于 2019-12-02 21:17:38
I have the following code: app.js [...] server.get(/\/docs\/public\/?.*/, restify.serveStatic({ directory: './public' })); server.listen(1337, function() { console.log('%s listening at %s', server.name, server.url); }); And I have the following file structure app.js public/ index.html So I try browsing: http://localhost:1337/docs/public/index.html and I get { code: "ResourceNotFound", message: "/docs/public/index.html" } I tried with several variations, but none of them seemed to work. I'm sure it should be something pretty obvious I'm missing restify will use the directory option as a prefix