Hyperledger Angular App - error message: "Could not find API route" - angularjs

Using Hyperledger Fabric Composer I created a simple application.
However, when I try to interact with the application (which is served at http://localhost:4200), I keep getting the following error message:
Error: 404 - Could not find API route. Please check your available APIs.
This error message appears whatever I want to do (create new Participant/Asset, submit a transaction, ...)
I checked whether the error message had something to do with the application I created. So I also deployed another application I downloaded from the Internet. Again, the same error message appeared when I tried to interact with the UI.
**********************************************************
Here's the long story:
After I had finished writing the code, I took the usual steps to obtain an Angular Web App:
Inside the folder of the app ("my_app"), I created a folder called "dist".
Inside folder "dist" I ran the following commands:
composer archive create -t dir -n ../
composer network install --archiveFile my_app#0.0.1.bna --card PeerAdmin#hlfv1
composer network start --networkName my_app --networkVersion 0.0.1 --card PeerAdmin#hlfv1 --networkAdmin admin --networkAdminEnrollSecret adminpw
composer card import -f admin#my_app.card
//start rest-server:
composer-rest-server
yo hyperledger-composer
After the last command I chose (from the menu) the option to create an "angular" application based on the business network "my_app".
A folder containing the angular-application was created (name of the folder: "angular").
Inside folder "angular", I ran the following command:
ng serve
Some output on the command line was created, among others, the following line:
** NG Live Development Server is running on http://localhost:4200 **
When I went to address http://localhost:4200 everything looked fine at first.
However, whenever I click on any of the buttons in the UI (e.g. on "Add Participant"), I get the following error message:
Error: 404 - Could not find API route. Please check your available APIs.

I found the solution:
using
"npm start"
instead of
"ng serve"
avoids the problem.
FYI. There is a tutorial that shows use of the Composer Angular generator incl the npm startsequence.

I had the same issue and got the same error messgae. So i recreated the angular application using the yo hyperledger-composer tool but this time instead of choosing "Connect to existing REST API" I chose "Create new REST API" and then it connected fine on localhost:4200 while the rest server still ran on port 3000.

I just ran into this problem with version 0.20 of the Composer CLI tools. I solved the issue by editing the following in the /package.json file:
The "start" entry originally had "0.0.0.0" for the host value -
"scripts": {
"ng": "ng",
"build": "ng build",
"prepack": "npm run build",
"start": "ng serve --proxy-config proxy.conf.js --host 0.0.0.0",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test --watch false",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor"
}
I changed that to "localhost" -
"scripts": {
"ng": "ng",
"build": "ng build",
"prepack": "npm run build",
"start": "ng serve --proxy-config proxy.conf.js --host localhost",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test --watch false",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor"
}
Everything worked after restarting the Angular app with the new settings.

I also encountered this error, I resolved it by running the composer and the angular app as a background process.
I installed the forever package to run the two as a background process.
Then just killed the process if you're not gonna use it.

Related

React/Next app keeps giving me an error about missing prerender-manifest.json

I have an application that is a combination of a node middleware server and a next.js front end gui with react components. It was running ok, but then, when I tried to build it in production mode, I keep getting the following error:
UnhandledPromiseRejectionWarning: Error: Cannot find module 'C:\Users\mgardner\workspace\qa-tool-backoffice\.next\prerender-manifest.json'
Require stack:
- C:\Users\mgardner\workspace\qa-tool-backoffice\node_modules\next\dist\next-server\server\next-server.js
- C:\Users\mgardner\workspace\qa-tool-backoffice\node_modules\next\dist\server\next.js
- C:\Users\mgardner\workspace\qa-tool-backoffice\server.js
I'm a little confused as to how to get the next front end to run concurrently with the node/express server. Here's my package.json file:
{
"name": "ibo-ui",
"version": "0.1.0",
"private": true,
"scripts": {
"mockdb": "json-server --watch public/mockdb.json --port 3001",
"dev": "concurrently --kill-others \"json-server --watch public/mockdb.json --port 3001\" \"npm start\"",
"build": "next build",
"start": "node server.js && next start"
},
The reason this was happening was because my next build process was failing. It was failing because I had some old react functions in the public pages folder.
The issue was that my pages not generated at build time in Nextjs correctly due my path included not correctly try to check your page collecting data fully and pages generated correctly.

How to set PUBLIC_URL back to the server root for npm run build

I made a simple react app, and wanted to deploy it.
At first, I tried npm run build. I got "The project was built assuming it is hosted at the server root."
I needed to deploy the app to my web server, so found a solution that worked:
set PUBLIC_URL=http://example.com/sampleDir&&npm run build
However, the next time I type npm run build, the message is always The project was built assuming it is hosted at "whatever path I set just before".
I tried set PUBLIC_URL='root' to set back to the original condition. But the message I got after executing npm run build was not the same as the first time.
Rather it said: "The project was built assuming it is hosted at root/."
If anyone knows, please let me know how to return this situation to the original: "The project was built assuming it is hosted at the server root."
1.
Unfortunately, my command line does not recognize 'unset':
'unset' is not recognized as an internal or external command, operable program or batch file.
(it seems that your way should work fine, and other google searches support it... I'll have to search more about it later)
Fortunately, though, the next line worked:
set PUBLIC_URL=&&npm run build
I'm not sure why... probably because I'm using cmder as my command line???
2.
Your package.json advice was tried, too.
My original package.json was like below:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
And, I changed it into yours:
"scripts": {
"build": "node scripts/build.js",
"build:sample": "PUBLIC_URL=http://example.com/sampleDir npm run build"
}
Then, I got an error message... (I'm not sure what this error exactly means...)
internal/modules/cjs/loader.js:584
throw err;
^
Error: Cannot find module 'C:\MyLocalDevFolder\scripts\build.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
at Function.Module._load (internal/modules/cjs/loader.js:508:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Anyway, after more searches, I could do what I want without contaminating the environment, adding the code below after the original "scripts" property in the package.json:
"homepage": "http://example.com/sampleDir/",
Thank you again for your advice, Tholle~
Happy coding~~~

How to deploy React build folder to Heroku

 I looked around the internet for this and found this medium article using serve. The article directed modifying the packange.json file to this:
"scripts": {
"dev": "react-scripts
"start", "start": "serve -s build",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"heroku-postbuild": "npm run build"
},
Now this works in development. I get console logs saying Content is cached for offline use. And google Lighthouse gives me >90% on progessive web apps. The problem is, when I deploy to Heroku, during build it runs the npm run build specified in the package.json scripts. But on opening the app, I get 21% on performance, and 50% on progressive web apps in firehouse. Also, it says service worker not registered. Which means it is not serving from the build folder. As an extra, I ran npm build myself in development machine and deployed the project TOGETHER with the build folder, but still same result. Now I also came around this other articlesuggesting to use node.js server and change scripts in package.json to this:
start: "node server.js"
I no nothing about node.js, so I decided to consult here for better choices.
EDIT: If a server command is needed, like in the node.js in the second medium article, and in Garesh's php code below - if anyone could help with a similar code in python(django), it'd be nice
Found the answer to this in this comment online:
Before deploying the app go to:
Heroku dashboard > settings > buildpacks > add buildpacks and then add github.com/mars/create-react-app-b...
Or, in command line you can do
heroku buildpacks:set github.com/mars/create-react-app-b...
If you don't do this step, heroku will deploy the development build (which is slow) of your react app instead of the optimized production build.
Build you code with:
npm run build
Now Put this code in the index.php file:
<?php header( 'Location: /index.html' ) ; ?>
Now put this index.php file into your build folder.
Copy this build folder somewhere else.
Now configure your new folder with your heroku app.
then
git push heroku master

How to add flowtype to an ejected create-react-app?

We are working on a previously ejected create-react-app and now want to add flowtype.
We have followed the guide at: https://flow.org/en/docs/tools/create-react-app/
Should that work for an ejected app?
This has unfortunately caused the webpack-dev server launched with yarn start to stop automatically reloading on file updates.
Additionally, after adding // #flow to some files there is no output or indication of flow enforcing type checking.
Will we need to manually update the webpack configs?
Heres the package.json scripts
"scripts": {
"start": "node scripts/start.js",
"build": "yarn build-client && yarn build-server",
"build-client": "node scripts/build.js",
"build-server": "./node_modules/.bin/webpack --config ./config/webpack.server.config.js",
"test": "node scripts/test.js --env=jsdom",
},
The output for running yarn start is:
Compiled successfully!
You can now view cra in the browser.
Local: http://localhost:3000/
On Your Network: http://192.168.1.65:3000/
Note that the development build is not optimized.
To create a production build, use yarn build.
The doc you linked tells you how to install the flow-bin and to make a configuration file but don`t tells how to launch it.
Flow is separated tool that should be launch by own command (depends on how you wanna run it):
if you want to check types check manually, you need to add npm command on the "scripts" section of your package.js: "example-comand-flow": "flow". Then call it by npm run example-comand-flow and you`ll get errors directly on a terminal you running the script.
if you wanna have continuing type checking, you should find a manual how to configure it in your IDE. For example, in WebStorm you should go Preferences -> Languages & Frameworks -> JavaScript and set JavaScript language version to Flow and specify flow executable.

React tutorial - how do I start the node server for a reactJs application?

I'm just starting the react.js tutorial, I've downloaded the files and then it mentions:
"Follow your progress by opening http://localhost:3000 in your browser (after starting the server). "
I know this may sound stupid, (bear with me since I'm a beginner with React) but how do I start the server in this instance?
Thanks.
Marc
Pretty solid chance it's npm start from the project root.
Properly packaged modules will have some node scripts configured in package.json. It's customary to use start as the script to run the dev environment, though some might use build, dev, or other names.
Here's official installation process: link, and officially recommended tutorials
# install react cli
npm install -g create-react-app
# create app
create-react-app my-react-app-name
# go to project folder
cd my-react-app-name
# install dependencies
npm install
# start live server
npm start
output:
$ You can now view my-react-app-name in the browser.
$ Local: http://localhost:3000/
$ On Your Network: http://192.168.0.105:3000/
$ Note that the development build is not optimized.
$ To create a production build, use npm build.
You can run any one of the below mentioned commands to start the node server for your ReactJS application:
npm run-script start
npm run start
npm start
All the above commands are equivalent but people prefer the third one as it is the shortest to type on keyboard.
The start parameter in these commands maps to the start key present under scripts configuration present in package.json file of any ReactJS application. Here is a sample package.json file of my hello-world application:
{
"name": "hello-world",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^15.4.2",
"react-dom": "^15.4.2"
},
"devDependencies": {
"react-scripts": "0.9.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
You can see that react-scripts start is written in front of start key. So react-scripts start command will get fired when we run any of the three commands which I had enlisted in the beginning e.g. npm start.
I used Node to run the server. The steps I followed are:
I downloaded the zip package from the Running a server section
here
I had the link open: http://localhost:3000/
I opened up Node.js Command Prompt and navigated to the downloaded
zip project. From Node example here:
Just type the commands in the example:
First npm install and then
node server.js.
See the screen shot below:
When I refresh the localhost web page I see the following:
Sounds like you're following the official React tutorial, in which case the instructions to start the various included server implementations are here.

Resources