eyn
eyn

Reputation: 798

how can I use express code to map a route in a sails hook?

In express code:

var kue = require('kue');
var express = require('express');
var ui = require('kue-ui');
var app = express();
app.use('/api', kue.app);
app.use('/kue', ui.app);

I can access: http://localhost:1337/kue and http://localhost:1337/api just fine.

I tried to move this into my sails hook:

var kue = require('kue');
var ui = require('ui');

module.exports = function galaxyKueSyncHook(sails) {
   return {
        routes: {
           before: {
              'get /kue': ui.app,
              'get /api': kue.app
           }
        }
   };
}

It doesn't work. I get a blank pages when access the same URLs.

How do properly get this to work in sails?

Additionally, I was able to get express code to work in config/http.js with

module.exports.http = {
    customMiddleware: function (app) {
       app.use(...);

But, I really want the function to be added in an installable hook.

Upvotes: 0

Views: 154

Answers (1)

alvaropaco
alvaropaco

Reputation: 1682

You can use express like:

var app = sails.hooks.http.app;
app.use('/api', kue.app);

Upvotes: 1

Related Questions