Changing the default Sails public folder - node.js

I know from experience that Sails creates a ./.tmp/public/ folder from where it serves all my files. I'd like to change it to just ./public/
I read a GitHub issue that said I could do it in config/local.js, but that doesn't seem to be working. Here's the GitHub issue: https://github.com/balderdashy/sails/issues/709
Is there a way to accomplish this? Thanks.
As to why I'm trying to do this, it's because I'm actually trying to work with Sails and Parse to build a simple test application. Since Parse looks in the ./public/ directory by default and I couldn't find a way to change this behaviour, I'm trying to configure Sails.

Create a file config/paths.js with the value:
module.exports.paths = {
'public': 'assets/'};

As in the mentioned issue report it can either be done in the .sailsrc file
{
"paths": {
"public": "bar/foo"
}
}
or if you launch sails in your own app (no using sails lift)
var Sails = require('sails');
Sails.lift({
paths: { public: 'mydir/pub' }, // relative to appDir
}, function(err, server) {});

If your using out of the box Grunt tasks, then you will need to go through and edit those tasks in <root>/tasks/config, there does not seem to be an global config variable for this, so you might have touch each file.
http://sailsjs.org/documentation/anatomy/my-app/tasks/config

Related

How to disable function logs on Gatsby?

So, I am new to gatsby and I am trying to build gatsby functions the way it is written in this documentation: https://www.gatsbyjs.com/docs/reference/functions/getting-started/
However, whenever I execute the function, it logs something like "Executed function "/api/test" in 27ms".
Now, since this will be a frequently called function in the future, I wish to disable the logs preferably just for this function OR for all the functions under /api folder.
Can anyone help please me out?
Try using gatsby-plugin-remove-console plugin:
module.exports = {
plugins: [
'gatsby-plugin-remove-console'
],
};
There isn't any built-in method of disabling logs as far as I know so try using the plugin. However, I'm not sure about its use in Gatsby functions...

nopCommerce store with a custom plugin web deploy issue

NopCommerce version: 3.9
I've designed a web store using NopCommerce 3.9. Any code I added is in a plugin.
The store uses a front page that can be found in the plugin. It relies on a route called 'home' in a RouteProvider class in the plugin. It does not complain about that route, instead it complains about a route named 'RegisterVendor' found in the same file. Here are both routes
routes.MapRoute("home",
"",
new { controller = "AoiVendorsHome", action = "Index" },
new[] { "Nop.Plugin.Other.AoiVendors.Controllers" });
routes.MapRoute("RegisterVendor",
"register/designer",
new { controller = "AoiExchange", action = "RegisterVendor" },
new[] { "Nop.Plugin.Other.AoiVendors.Controllers" });
The plugin installs properly and everything works exactly as expected on my local machine.
The problem is after deploying to the web it can't find the route. Here is a imgur link, follow it to see the error
Restarting the server fixes the error for a while, but it does eventually come back. It also comes back any time I redeploy without restarting the server afterwards.
Does anyone have any ideas?
Thank You.
The "HomePage" route of nopCommerce is registred this way
//home page
routes.MapLocalizedRoute("HomePage",
"",
new { controller = "Home", action = "Index" },
new[] { "Nop.Web.Controllers" });
Check your load order: If your registration does not hit first, remove nopCommerce "HomePage" route and add yours or add yours first using the Priority property of IRouteProvider.
MVC uses the route that first matches the request.
Regarding the deployment problem, make sure your plugin is deployed to ~/Plugins/{yourPluginFolder} and not the bin folder of Nop.Web. Plugin in ~/bin folder can be loaded but without guarantee.
I was able to fix the issue by selecting the 'Remove additional files at destination' checkbox under file publish options on the settings tab in the publish popup dialog in visual studio. I imagine an older file was not being overwritten and was causing problems.

How can I access the hapi plugin name?

I am working on node using hapi framework. New to this so I apologize if it comes out to be very basic.
I want to access a plugin name within the plugin files.
Use case is I want to access the plugin options from the server object.
So I can do server.registrations[plugin_name].options.
My workflow at that point (where I require the options) is not inside the register method ( I run an independent script that just needs to initialize the server, not start it; so no routes here) so not able to access the options from there, but I have the server object available.
Also, what is the correct way to expose the plugin options to other files within the plugin? If I need the options after a lot of nesting of files etc , it is very chaotic to keep passing the options object somehow from file to file, method to method.
Not really clear how to work this problem out.
Not a 100% sure what your question is but if you expose your options in a script (module) that can be required by both your plugin and any other files that you want to use the same options object that will allow you to access the same object in multiple places.
Please let me know if i understood correct, you can do like this.
const Plugins = require('./Plugins');
//Register All Plugins
server.register(Plugins, err => {
if (err){
server.error(`Error while loading plugins : ${err}`)
}else {
server.log('info', 'Plugins Loaded')
}
});

CRUD blueprint overriding in sails.js

According to this closed issue in sails:
https://github.com/balderdashy/sails/issues/835
CRUD Blueprint Overrides
"absolutely, this is coming in v0.10"
I'd like to modify the blueprints in my sailsjs service to allow named roots (consuming in ember).
Currently I'm having to customize every controller I create with actions that are largely duplicates of what is already in the blueprints.
I suspect that I can move this code out of my controllers now and into a blueprints override area, but I'm not clear on where to put that code.
Any examples or even just a pointer to the relevant code in sails the .10 repo would be greatly appreciated.
Update
In order to override blueprints in Sails 1.0 in the manner described below, you must first install the "custom blueprints" plugin for your project (npm install sails-hook-custom-blueprints).
To override blueprints in Sails v0.10, you create an api/blueprints folder and add your blueprint files (e.g. find.js, create.js, etc.) within. You can take a look at the code for the default actions in the Sails blueprints hook for a head start.
Adding custom blueprints is also supported, but they currently do not get bound to routes automatically. If you create a /blueprints/foo.js file, you can bind a route to it in your /config/routes.js file with (for example):
'GET /myRoute': {blueprint: 'foo'}
you can add actions with these names inside your controller to override default behaviour
to change destroy behavior
module.exports = {
destroy: function(req,res){
Goal.update({ id: req.param('id') }, { deleted: true })
.exec(function (err, goal) {
if (err) return res.json(err, 400);
return res.json(goal[0]);
});
}
}
It is possible to use the build in blueprints, but with policies running first. These policies might verify that the user is logged in, has the correct access, or similar. Really handy!
On each model, you have available callbacks both before and after data has been stored. Dig in: http://sailsjs.com/documentation/concepts/models-and-orm/lifecycle-callbacks
There is no default callback available for blueprints result. But don't give up. It is still possible to use the build in blueprints, and only modify the output. It might not be the most elegant solution, but it works well. Check out my “hack” here: Sails blueprints lifecycle

Adding paths to RequireJS configuration on runtime

Ok, I already know that you should configure paths with RequireJS like this
require.config({
paths: {
name: 'value'
}
});
And call it like this.
require(['name'], function() {
/* loaded */
});
But the thing is, I'm working in environment in which I don't have access to the existing call to require.config(...). For those who care, the environment is Azure Mobile Services scheduled job. Microsoft has already included RequireJS in the environment and configured the paths. My question is two-fold.
1. How do I add paths to the existing require.config()?
I know calling require.config() again will destroy the existing configuration. Which is what I do not want to do.
2. How do I get to know which paths have already been configured?
I really wouldn't like to overwrite any existing path name or overwrite any existing library by accident.
Running require.config() again does not override your original config file. It actually extends it and adds your new paths to it. Right now I am using it this way, where configfile is also a require.config({})
<script data-main="configfile" src="require.js"></script>
<script>
require.config({
paths: {
prefix-name: 'path/to/file'
}
});
</script>
One way to avoid name collisions with Azure Mobile paths would be to simply prefix all your custom paths.
Disclaimer: I have never used Azure Mobile, just RequireJs. You may have to implement it a little differently but it is possible.

Resources