-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Seneca Web does not listen to 'X-HTTP-Method-Override' #89
Comments
Ultimately seneca web just creates routes with Hapi / Express. If it is something that needs to be done per route we can add pass through config. As of 1.0 the only thing seneca web does so you need to set the above in hapi or express, ala, hapijs/hapi#1217 |
Usually you would be able to use the npm module method-override written by const methodOverride = require('methode-override'); On Fri, 16 Sep 2016, 15:09 Dean McDonnell, notifications@github.com wrote:
|
This should work - but it depends on when it has been loaded into the middleware chain. If you follow the quick start example they pass The following should work: const Express = require('express')
const Seneca = require('seneca')
const SenecaWeb = require('seneca-web')
const app = Express()
app.use(methodeOverride('X-HTTP-Method-Override'));
const seneca = Seneca()
seneca.use(SenecaWeb, {context: app, adapter: 'express', routes: '...'})
seneca.ready((err) => {
// app's routes now has:
// [methodOverride, ...senecaRoutes]
}) Typically what I've been doing is setting up express with all the middleware it needs (i.e., body parser, session, etc., etc.) and passing This allows for dynamic routes to be added later from microservices joining the mesh, while still keeping the last |
What is the difference between that and this? Is it the points at which I load the modules? // ========================================================= CONFIGURE EXPRESS ======================================================= //
// create the express framework
const app = express();
// override with different headers; last one takes precedence
app.use(methodOverride('X-HTTP-Method', ['POST', 'PUT'])); // Microsoft
app.use(methodOverride('X-Method-Override', ['POST', 'PUT'])); // IBM
app.use(methodOverride('X-HTTP-Method-Override', ['POST', 'PUT'])); // Google / GData / Salesforce
// Protect against known vulnerabilities
app.use(helmet());
app.use(helmet.noCache());
// Set up Passport
app.use(passport.initialize());
app.use(passport.session());
app.use(compression());
app.use(express.query());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(pmx.expressErrorHandler());
// ========================================================= CONFIGURE SENECA ======================================================= //
// create a seneca instance
const seneca = require('seneca')({ timeout: 15000 });
// load seneca modules
seneca.use(require('seneca-web'));
// load custom seneca modules
seneca.use(__dirname + '/seneca_modules/data'); // data access layer
seneca.use(__dirname + '/seneca_modules/documentation', { app: app }); // documentation
seneca.use(__dirname + '/seneca_modules/core-api', { passport: passport, app: app }); // application layer
// ensure seneca is configured to use passport
require(__dirname + '/seneca_modules/core-api/config/passport.js')(passport, seneca);
// initialize the seneca modules
seneca.act({
data: 'initialize'
}, (error, output) => {
console.error(error || output.message);
});
seneca.act({
model_version: 'v2',
controller_version: 'v2',
documentation: 'initialize'
}, (error, output) => {
console.error(error || output.message);
});
seneca.ready( () => {
app.use(seneca.export('web'));
// start seneca!
seneca.listen();
seneca.log.info('listen', configuration.node_port );
}); |
This is the old way of using the code let me change it for you. |
See https://github.com/senecajs/seneca-web#auth passport is now directly supported on the routes. You need to add in your routes to the empty object or you can add them after seneca.ready too. The old seneca-web used to return a middleware but this caused issues in load order. The new one just adds routes so it is up to you to start expres/hapi/koa/etc yourself. PS all acts should happen after ready in seneca. |
so where i used to get my routes from was using this line seneca.use(__dirname + '/seneca_modules/core-api', { passport: passport, app: app }); // application layer and that had this in it 'use strong';
var seneca = require('seneca')();
var version = function (options, number, current) {
return function (app) {
// route prefix builder
var version = '/v' + number;
var prefix = options.prefix || '/api';
if (current) {
require(__dirname + version).routes(app, prefix, options.passport);
}
prefix += version;
seneca.log.info('API prefix', prefix);
require (__dirname + version).routes(app, prefix, options.passport);
};
};
module.exports = function (options) {
var router = this.export('web/httprouter');
// handle the routes for each version of the API
// NOTE: /api points to the last version denoted as 'current'
// this.act('role:web',{use: router(version(options, '1' )) }); -- V1 DEPRECATED
this.act('role:web', {
use: router(version(options, '2', 'current'))
});
return { name:'api' };
}; So i no longer need the web/httprouter export and i should just get my routes directly from this line require(__dirname + version).routes(app, prefix, options.passport); |
@devotox without seeing your codebase in full it is hard to tell what exactly you require changed. Generally though, you should only have to build a map of the routes and pass it, express, and passport into seneca-web. See the secure routes examples we have in /eg for the changes. |
@devotox It has been primarily tested with 3.0 It may work with 2.0. Please report any issues and we will fix it up so it works as expected where possible. |
Ok i think i understand now thank you. |
If you need any more help please add issues, cheers! |
How can we get Seneca Web to change Paths based on an X-HTTP-Method-Override as there is no way to send a patch request from certain systems
The text was updated successfully, but these errors were encountered: