I am a complete and utter beginner. I am working through some classes to begin my learning journey so if I am just way over my head and need to go get some additional training I am all ears for pointing me in that direction. That being said the class I'm in currently is using heroku to launch an app. I did everything the instructor did but had to create a package.json because it wasn't satisfied with my index.php (the instructor did not have to create a .json but noted some students have had this issue in the past). My index.php bring me back to my first ever computer class many years ago:
<?php
echo 'Hello World';
?>
My Json is also very basic (the instructor just told me to use { } but I wanted to write a small string)
{
"string" : "Hello World!"
}
The intent of this is just to launch an "app" that says hello world. But every time I keep getting an application error. I have been trying to figure this out all morning and think I went a bit too deep into the rabbit hole just trying to do a seemingly simple task.
Log image:
I'm not entirely clear whether you are trying to run a PHP application or a Node.js application, but either way Heroku needs to know how to run it.
For Node.js projects, you can tell it in one of two ways:
By adding a Procfile that defines you process types. The file must be called Procfile exactly.
If you run your application with the command node index.js and your application listens for HTTP requests, you can define a web process that looks something like this:
web: node index.js
This method is the "standard" Heroku method and it works for all runtimes.
The Node.js runtime has a fallback if a Procfile is not found: it will run the start script in your package.json.
If you want Heroku to run node index.js you might have something like this in your package.json:
{
"scripts": {
"start": "node index.js"
}
}
If you have a PHP project instead, your Procfile might look something like this:
web: vendor/bin/heroku-php-apache2 public_html
In either case, I don't recommend doing this:
I wanted to write a small string)
{
"string" : "Hello World!"
}
The package.json (for Node.js projects) and composer.json (for PHP projects) are not free-form JSON files. They are expected to take a particular shape, having certain keys, and having semantically valid values.
It is fairly common to ship simple PHP projects with a composer.json that just contains {}, but I haven't seen that for Node.js projects and package.json.
Either use an empty object like your instructor suggests, or build a proper file using valid keys and values.
So after some tinkering. Changing the .json from packages.json to composer.json did the trick. Heroku provisioned the packages and all is well.
Thank you to the awesome community here. It's nice to know as a complete newb people are willing to help out.
Related
I want to build a web page where I separate Database, Backend and Frontend and make then communicate via REST. I got quite confused about how to structure the project(s). As I read, there are the following approaches:
Make different projects: one for the frontend (let's say Angular) and one for the Backend (Spring) including the database connection. These are completely separated from each other and different IDE's might be used.
Build it in one big project but still use REST for communication (see picture below).
Now what I would like to know is what the difference between these two approaches is? I do not know (and do not ask) which one is the better one, but I cannot even make out reasons or effects to pick one above or below the other one.
This is really question about personal preference, but you have them be in completely different projects and at the same time you can put your JS bundles (from ng build) inside of the resources/static folder (of the Spring app) and it'll work perfectly, assuming you want to run them on the same server.
You can set a proxy config to make it easier like:
{
"/api": {
"target": "http://localhost:8080",
"secure": false
}
}
This way whenever you do a rest call with something like Angulars HttpClient, as long as you put /api in front of the url it'll call your spring backend.
Example:
public fetchResource(id: number): Observable<Resource> {
return this.http.get(`/api/resources/${id}`);
}
I prefer to have my client and api in different projects.
Whenever you want to add the JS bundles to your resources/static folder, you can just create an NPM script to do it for you in package.json.
I am a new NativeScript user and I am trying to understand how to have my app make a GET call to a remote server, depending upon environment. In Java world we pass in an environment variable, but I have not found an example (that I understand) demonstrating how my NativeScript mobile app will know which environment it is running in, and how to get values based upon that.
I am presuming that I will have a config/ with files such as
prod.conf.js and dev.conf.js - and there is where I will put in my urls and other config values.
How do I get my NativeScript (which I will eventually build into iOS) to reach those values to use in an http request upon startup. Any example to direction to documentation would be greatly appreciated.
Answer:
I finally got the problem solved by using Manoj suggestion of nativescript-dev-appconfig. For any newbie looking for help, try this:
{PROJECT_ROOT}/config - create the environment files as {env}.json. These files are just json, with name-value pairs of the values you want. In may case that is
When you do your build: tns build ios --bundle --env.config {dev | test | prod }
This will take the contents of the selected env.config file (ie -env.config dev and copy it as - {PROJECT_ROOT}/app/config.json .
To use it within your code,
import config from "../config.json";
axios.get(config.MY_URL).then(result => {...}
Unfortunately using environment based config files are not officially supported but there is a plugin hook you could try.
We also have webpack based environment variable support, read more about that in the docs.
Need to reduce my project folder memory size. so that, changed the following line in bootstrap/autoload.php
require DIR.'/../vendor/autoload.php';
changed to
require 'home/sites/laravel/myApp/vendor/autoload.php';
But all the Controller actions are called from main Application instead of sub application.
My Folder Structure,
.MyApp
vendor
.MyApp1
Include the vendor from myApp
Don't do it. It's a seriously bad practice and it also breaks everything you specify in your composer.json file, with a different state in production than expected. As the other guys told you before me, this would break your app at every dependency change.
I don't know how much big your app is. However, if you are deploying your app to a remote server, just try to get more space from your provider. If you're working locally, this is not a problem you should have anyway :)
I am developing a simple CRM app using Laravel 5.2 and ReactJS. Previously I was using them independently, but now I want to try to combine them together so Laravel will be my API and front-end will be all in ReactJS.
As far as I know when my app is ready to go live I will serve my master view which includes root div, bundle.js etc.
When it comes to development part I am a little confused. I really love react hot reload, but for now I had to do a little walk around to make this works.
I run two servers side by side. Webpack-dev-server and homestead, so I am able to do calls to my API. But I also have to have additional index.html for webpack-dev-server. When i change something in my index.blade.php view I also need to change this in this index.html and this is a little bit of pain.
Is there any cool trick that I can apply to improve my workflow? If there is any example please provide me a link, because I wasn't able to find one. There are many small todo apps that doesn't really solve my problem.
PS. Currently I am using this approach https://github.com/sexyoung/laravel-react-webpack
#UPDATE
Well I think I have found an acceptable solution. I will stick with webpack server configuration that I have provided in my question (it is really great cause you can use hot reload + you api calls are redirected to backend port, so instead of localhost:8080/api/user... you call /api/user/1), but I have also developed a simple elixir extension that compiles php to simple static HTML page which solves the problem of editing two index files (we all know programmers are lazy).
var php2html = require("gulp-php2html");
var gulp = require("gulp");
var rename = require("gulp-rename");
var Task = elixir.Task;
elixir.extend("php2html", function (message) {
new Task("php2html", function () {
return gulp.src("./resources/views/index.blade.php")
.pipe(php2html())
.pipe(rename('index.html'))
.pipe(gulp.dest("./"));
})
.watch("resources/views/index.blade.php");
});
elixir(function (mix) {
mix.sass('app.scss');
mix.php2html();
});
So at the moment I have two index files:
index.blade.php in resources/views which is resolved by the router on production
index.html in root of my application folder which is used by webpack-dev-server for development
and of course now these files are sync cause of gulp watch :)
If there is any better approach let me know guys.
I have usually solved this problem (duplicated index.html/php file) using this webpack plugin: https://github.com/ampedandwired/html-webpack-plugin
The idea is the opposite of yours I think. Instead of compiling your php files into static html, you can use the HtmlWebpack plugin to output a index.tmpl.php file (or whatever extension you need) using the filename configuration option. Normally I set that path to be the templates folder of my application server.
I believe this approach is generally easier than doing the other way round.
Using this plugin has other benefits, such as automatic bundle script tags injection depending on your Webpack output config, and automatic cache-bursting file hash added to the script tag urls.
I thought of creating a constants.php file in the config directory but didn't go ahead with it as it kinda contradicts the idea of "CONSTANTS" as anything in config can be changed at run time. So what are the best practices in storing constants in a laravel project without too many "require_once"s or "use"s ?
pointer to some public git project which uses a standard way to get this done would be great.
you have to make constant in one file and use all over laravel than you have to make one file that can we write all the constant and costume functions.
Follow the steps
Make one Helper.php file in the your app->Http directory.
Write the all the constant and function there.
Then make following changes in your composer.josn
"files": [
"app/Http/helpers.php"
],
Then following command in your laravel project directory.
$ composer dumpautoload