Configuration files : JS vs INI [closed] - javascript

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I need to implement configuration files for an application im developing.
I was wondering whether it is better to use INI files or JS files(JSON data)
for the configuration files.
What are the security concerns? Could a file permission be set to the js files that a user cannot retrieve them via the browser but the php can read them?

Best way to handle that kind of configuration is to keep it outside of your public directory, so that users won't be able to access it.
Generally in web applications you have web-accessible directory. For example: web/ in Symfony 2.x and public/ in Laravel 4/5. In these folders you would usually find index.php file which user runs when accesses your website. If you move your file outside of this folder - (cd ..) - into your application root directory where you might see directories like vendor/ then here you could store files which ordinary user would not be able to download just using some link to the file.
About file extension. Actually lately it has become quite popular to name your config files in "dot" format. For example: production or .my_config which not only protects you from users accidentally downloading files (since dot files are usually not accessible), but it also lets you keep your config files out of version control software such as git, so your passwords won't end up on github.

Related

How to use personality-insights-chart? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I created my own API using the IBM Watson Personality Insights API. Then, I created a website that would retrieve the the JSON object from the API and display it in a sunburst diagram, just like in the Personality Insights Demo.
I have found a library that displays the information how I want from a JSON object: https://github.com/personality-insights/sunburst-chart . The problem is that the instructions say that I must insert this two lines of code into my HTML file:
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.14/d3.min.js"></script>
<script src="path/to/personality-sunburst-chart.standalone.js"></script>
I know the second line must be changed accordingly to where personality-sunburst-chart.standalone.js is, but that file doesn't exist in the library. I thought that maybe they had changed the library and forgot to update the instructions, so I tried pointing it to index.js file inside the /lib folder of the library. Once I did that the browser console started alerting me that the file couldn't be executed because it contained require() commands, that can't be executed in web JavaScript.
Where can I get the missing file?
I found the answer.
Explanation
In all 1.x.x versions of the library, the whole library came precompiled in the /bin directory in the form of a JavaScript file named "personality-sunburst-chart.standalone.js".
The current version is 2.x.x, the installation method changed, but the instructions weren't changed.
Current installation instructions for the 2.x.x version
The current version doesn't come with a precompiled file. To get it, you have to follow the following instructions:
You have to download the repository and run npm install to install all the necessary dependencies. After that, you must run npm run compile. Once that finishes, the standalone file will be in the /dist directory with the name index.js.
The command script is: node_modules/.bin/browserify --full-paths -t [ babelify --presets [ es2015 ] ] --standalone PersonalitySunburstChart lib/index.js -o dist/index.js
You can then change the name to "personality-sunburst-chart.standalone.js" if you want and copy it to your web page directory.
Then, you can reference the final script with :
<script src="personality-sunburst-chart.standalone.js"></script>

Angular 2 build generates links to root of server [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I`m trying to make my project runs in a test server, but when I run the ng build command and take the data from dist to there it always tries to load the js and css files from myserver.com/ and not from myserver.com/folder-of-project/
I thought it would be a problem on my code, but I created an empty project with angular-cli and did the build directly and also I got the same problem.
Am I missing something to do in the code before preparing the build?
Run ng build --env=prod this will build your project for production. ng-build it for local development. Also make sure inside your index.html the base href is as follows: <base href="/">
As mentioned in the comments, you'll need to append your project folder to your base href inside your index.html file
like so
<base href="/folder-of-project">

Automatically create grunt environment [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm a little lost as to how I should proceed, actually I don't even know where to start.
I've been working on a few wordpress sites lately, usually I create a dev environment using npm grunt.
I set up a folder and do npm init. Then I install all the grunt plugins I need such as: watch, sass, uglify etc... I then download wordpress and set up the gruntfile.js so that for example my sass will compile to my wordpress theme's stylesheet. Just the usual (I hope).
The thing is rather than always repeating the same step over and over I'd like to automate it ( same config step for each site ).
So here is my question, how do you go about creating a script that will automaticaly install grunt plugins and configure them, download the latest wordpress and set up the theme files ( domain name etc...)?
I don't need an explanation on how to do all these steps but just a few pointers on where to start and what tools to use would be great. Being quite the novice in script writing any information is good to use.
Try yeoman.
There is yeoman generator for wordperss boilerplate. It uses gulp instead grunt, but has same idea that you need.

Deploy minfied javascript files and debug [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
so i completed building a new angular application and i would like to deploy it into production... of course i have prepared all my angular code such that it can be minified so i am covered there!! But something i dont understand... i have very good code separation and full unit testing of my application... as a result, of course, there are a lot of script tags on my main page.
I need to of course debug my javascript during runtime as i develop, but then when i go to deploy i need to minify. What is the best practice here? Is this literally a manually process of replacing the script tags with my all.min.js file after i move the code to the production machine? Do i minify all the css and html as well?? I am using gulp for the minification...
thanks for the help....
In the absence of server side templating (like Razor or Thymeleaf) I would suggest using gulp-preprocess, gulp-processhtml, or gulp-html-replace.
Use gulp to concat your files in development as well as production. You'll probably want to use gulp-sourcemaps to be able to debug your client-side javascript as if they were separate files.
Here's a sample gulpfile.js
gulp.task('script', function(){
gulp.src('./app/**/*.js')
.pipe(sourcemaps.init())
.pipe(concat('application.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./build'))
})
gulp.task('script:prod', function(){
gulp.src('./app/**/*.js')
.pipe(concat('application.js'))
.pipe(ugilfy())
.pipe(gulp.dest('./build'))
})
Then in your view, just point it at the build file.
<script src="/build/application.js"></script>
When you deploy, run gulp script:prod. In development, run gulp script.

What's the preferred workflow for deploying coffescript? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Should I store .coffee files in git and compile them server-side with some git hooks, or should I store both .coffee and .js files in SCM and just ignore coffee at the server?
Are there any disadvantages to storing compiled .js files except extra SCM space usage? I'd rather not have to install node, npm and coffee on each server.
The workflows that I've seen are for Rails and Node. My current process is based on them and looks like:
Keep .coffee files in /assets/src/coffee
Keep compiled .js files in /assets/js and reference them as /js/foo.js
Keep .js files that are external to your app (e.g. a graphing utility) in /assets/lib
Exclude /assets/js from your source control
Set up your middleware to compile coffeescript files on the fly if they aren't already compiled. connect-coffee-script was the one I liked best.
The process in Rails is pretty similar, to the best of my recollection.
Are there any disadvantages to storing compiled .js files except extra SCM space usage? I'd rather not have to install node, npm and coffee on each server.
I see no good reason to put compiled js into source -- your middleware should handle turning coffee into js. I also see no disadvantage to installing coffee on your server -- you should be doing an npm update as part of your build process and that should take care of it.
Here's the code for setting it up:
var app = express();
...
srcFolder = path.join(__dirname, 'assets', 'src', 'coffee');
publicFolder = path.join(__dirname, 'assets');
app.configure(function () {
...
app.use(require('connect-coffee-script')({
src:srcFolder, dest:path.join(publicFolder, 'js'), force:true
}));
It's also important to note that I had some issues getting this going on Windows 7; node's file watchers seem to have some issues there. So I have to have a command window with this running while developing: coffee -o ./assets/js -wc ./assets/src/coffee.

Categories

Resources