return browserSync.init({
server: {
baseDir: ['.temp',
'.mer',
`${config.serve.mer}/views`,
`${config.serve.temp}/views`,
config.serve.mer,
config.serve.temp
],
port: config.serve.port,
https: true,
routes: routes
},
ui: {
port: 8080
},
notify: false,
open: false,
});
Server only supports GET request does not support POST request?
Thanks for the report :)
in what way does it not support POST requests? Please create a small sample project that highlights your use-case and I can look into it & re-open this issue :)
@shakyShane I have a dev environment SPA running with BrowserSync, and it all works fine, but I also ran into a use case where I had to have the server accept POST requests, and it failed with a Cannot POST /...url message.
The reason I need this to work, is that I am integrating with an online payment system, and that system will issue a POST request back to my SPA url. I cannot change that to a GET request. So, in order to test, I would like my dev environment server to accept such POST requests and serve the SPA index.html file.
I have resorted to using the following simple middleware to ensure both POST requests are converted to GET requests and everything is sent to the SPA middleware:
/**
* Static middleware
*/
let staticMiddleware = serveStatic(path.resolve(BASE_DIR));
/**
* SPA middleware
*/
let spaMiddleware = function(req, res, next) {
req.url = '/index.html';
req.method = 'GET';
next();
};
/**
* Initialize browser sync
*/
browserSync.init({
port: PORT,
server: {
baseDir: BASE_DIR,
middleware: [
staticMiddleware,
spaMiddleware,
],
},
});
Hope this helps someone. However, it would be nice if browserSync could have some kind of option or setting to make this easier.
@shakyShane Any update on this? I am trying to be able to accept other HTTP verbs besides GET
Most helpful comment
@shakyShane I have a dev environment SPA running with BrowserSync, and it all works fine, but I also ran into a use case where I had to have the server accept POST requests, and it failed with a
Cannot POST /...urlmessage.The reason I need this to work, is that I am integrating with an online payment system, and that system will issue a
POSTrequest back to my SPA url. I cannot change that to aGETrequest. So, in order to test, I would like my dev environment server to accept suchPOSTrequests and serve the SPAindex.htmlfile.I have resorted to using the following simple middleware to ensure both
POSTrequests are converted toGETrequests and everything is sent to the SPA middleware:Hope this helps someone. However, it would be nice if browserSync could have some kind of option or setting to make this easier.