What is the best way to develop *.js with ServiceStack self-host? - servicestack

Due "Copy to Output" for js files it is impossible to just edit js file and reload the page to see the changes. It is required to restart the service.
One of the possible solutions is to modify VFS to look at js files in the correct location (solution tree, not in the output folder) in DEBUG mode.
Any other suggestions?
Thanks,
Dmitry

The simplest solution is
SetConfig(new HostConfig
{
WebHostPhysicalPath = "C:\\projects\\path_to_self_host_project"
});

Related

Changing the default Sails public folder

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

ServiceStack: Self-Host LiveReload not working

I have a self hosted ServiceStack application which I intend to use to develop an angular application with.
The problem is, previously, every time I've made a change to a static file, I've had to restart all the services for it to pick up the changes.
I'm wondering if I'm missing something? I've enabled the LiveReload option from RazorFormat but it doesnt seem to have done anything? I still have to restart the whole application for it to pick up changes?
I've created a small repro here: https://github.com/CallumVass/ServiceStackSelfHost
If I make changes to the Default.cshtml file the changes arent picked up until I restart the service?
The issue is that he was changing the source file and not the output file. Since SS copies the files to /bin/debug he needed to change that version.
Using HostConfig settings, we were able to to use the WebHostPhysicalPath property in the following way during development, while setting up the SS Config:
SetConfig(new HostConfig {
#if DEBUG
DebugMode = true,
WebHostPhysicalPath = Path.GetFullPath(Path.Combine("~".MapServerPath(), "..", "..")),
#endif
});
This took us out of /bin/debug and back to the source.
You need to set the AppHost config to debug mode:
SetConfig(new HostConfig {
DebugMode = true,
});
For performance reasons changes are only monitored for in Debug mode. See here for more information.
Automatic reload of modified views, layout templates and partials (in Debug mode)
The best way to avoid the Start-Up penalty is to avoid having to restart the AppDomain in the first place. So in Debug Mode we'll also do this where a background file system watcher monitors all pages, partials and Layout templates for modifications and recompiles and auto-reloads them on the fly, all-ready to deliever instant response time once the page is requested.

How include properties file for internalisation?

I am working on a node JS project with the Kraken framework. Then I use Dust templating and makara for the internationalization. But actually, I have one .properties file for each .dust file and i would like include a main.properties for each other properties for sharing same content across the pages.
I try this in a properties :
include = main.properties
But it doesn't works.
Do you have an idea ?
Thanks you in advance.
There is no mechanism for include currently. This issue is the one to track on that matter: https://github.com/paypal/makara/issues/11

Drag 'n' Drop files to a Chrome Package App?

Has anyone successfully implemented drag and drop with files from desktop to the app?
I've tried just putting this drag 'n' drop example into the index file but I just get this error:
Can't open same-window link to "file:///C:/Users....whatever"; try target="_blank".
Please share your stories, what you've tried and if you have succeed :)
Some resources to help you:
New Chrome Packaged Apps codelab that we've been working on covers drag-and-drop in both AngularJS and pure JavaScript.
AngularJS drag-and-drop: https://github.com/GoogleChrome/chrome-app-codelab/tree/master/lab5_data/angularjs/2_drop_files
JavaScript drag-and-drop: https://github.com/GoogleChrome/chrome-app-codelab/tree/master/lab5_data/javascript/2_drop_files
There's an early version of docs too for AngularJS drag-and-drop for Chrome at developer.chrome.com/trunk/apps/app_codelab5_data.html#handle_drag_and_dropped_files_and_urls
We're working on the docs to cover both samples though.
I have done this a while ago and it worked.
The problem you've got is that you are creating a file url, then trying to navigate to the url. The navigation is failing, not the read. It's failing due to CSP, and you probably won't be able to override that with a different CSP due to security restrictions we've placed on allowable CSPs.
But, you should be able to just read the file and use the content. You need to change that sample code to use ReadAsText or ReadAsArrayBuffer instead of readAsDataURL. Look here for more details.
Please let us know how you get on!
Just listening for drop won't work. You will have to prevent the default functionality of dragover.
document.body.addEventListener('dragover', function(e) {
e.preventDefault();
}
document.body.addEventListener('drop', function(e) {
alert('it works!')
}

Is there a way change a node.js while it's running?

Is there a way change a node.js while it's running?
Like edit the javascript files while it's running and then it change accordingly while it's running.
Yes.
You'll have to load your file through another file that watches the script for changes. You will probably need some setup/teardown code that runs in the script whenever it is restarted.
var fs = require('fs');
var file = 'file.js';
var script;
function loadScript() {
if (script) {
if (typeof script.teardown === 'function') {
script.teardown();
}
delete require.cache[file];
}
script = require(file);
}
fs.watch(file, function(event, filename) {
if (event !== 'change') return;
loadScript();
});
loadScript();
The fs.watch API is not 100% consistent across platforms, and is unavailable in some situations.
Have you checked Node-supervisor
No, it is not possible. When you startup a Node server / app it will load in the current versions of the files. If you make a change after startup it will be unaware. You will have to kill the app and restart for these changes to take affect.
There are some utilities like node-dev which do this for you. They monitor the filesystem for changes and restart the app as needed (along with some other features like growl notification).
I prefer restarting the app manually. That way you know exactly what version it's running, and can save changes to a file multiple times before deciding to try it out again.
You can use nodemon.
nodemon will watch the files in the directory in which nodemon was started, and if any files change, nodemon will automatically restart your node application.
Perfect solution to work with Node during development.
This is totally possible.
Just don't require your modules in the header; instead, load them by calling at the time of need.
In addition, you can also call require.undef('./myModule') to ditch existing versions before including the new module. You can scan the file system for any new module names, if you feel like dropping in new behavior at runtime.
I have implemented the plugin pattern numerous times with node, such that a submodule update will include new plugins that will be picked up at runtime.
Enjoy.

Resources