Ionic4 http request not working on Android Device - ionic-framework

So far REST API get method working in my local ng serve , but in my device not working.
Android device remote debug showing :URL:'localhost/get/list'
proxy.config.json
"/code":{
"target": "http://192.x.x.x:8010",
"secure":false,
"changeOrigin": true,
"logLevel": "debug"
},
Serive Get Method:
this.service.getUrl('/get/list','level=2').subscribe(
data=>{ //Android Device URL :localhost/get/list not showing proxy.config.url
});
package.json
"start": "ng serve --proxy-config proxy.conf.json",
Remote Debug Result:**I can't get **_body result like local result , it's seems getting index.html page.
Local ng Serve Result:

If you are using the emulator and the API is on your local machine, change the IP address in proxy.config.json to 10.0.2.2. Check out How do you connect localhost in the Android emulator?

Related

Running flutter web app locally without android studio

I have a flutter app using Firebase's cloud firestore. I've done the web build and running it on Chrome through Android Studio works well. I would like to share my web app progress to my client but don't want to host it (because it's not finished yet). Hence I'd like to find a way to run it locally the same way you can do it with Android Studio but without needing to install Android Studio (and hopefully not requiring to install flutter either), so that I can send the build file to my client and they can run it in their machine (with a script to start the web server locally and run the web app).
I have tried the following script included inside the web build folder (where the index.html is)
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from httplib import HTTPResponse
from os import curdir,sep
#Create a index.html aside the code
#Run: python server.py
#After run, try http://localhost:8080/
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
self.path = '/index.html'
try:
sendReply = False
if self.path.endswith(".html"):
mimeType = 'text/html'
sendReply = True
if sendReply == True:
f = open(curdir + sep + self.path)
self.send_response(200)
self.send_header('Content-type', mimeType)
self.end_headers()
self.wfile.write(f.read())
f.close()
return
except IOError:
self.send_error(404,'File not found!')
def run():
print('http server is starting...')
#by default http server port is 80
server_address = ('127.0.0.1', 8080)
httpd = HTTPServer(server_address, RequestHandler)
try:
print 'http server is running...'
httpd.serve_forever()
except KeyboardInterrupt:
httpd.socket.close()
if __name__ == '__main__':
run()
But when opening http://localhost:8000 on Chrome I get a blanc page and the console shows the errors:
Failed to load resource: net::ERR_EMPTY_RESPONSE main.dart.js:1
Failed to load resource: net::ERR_EMPTY_RESPONSE manifest.json:1
Failed to load resource: net::ERR_EMPTY_RESPONSE :8080/favicon.png:1
I also tried NPM local-web-server by running ws --spa index.html but just getting a ERR_EMPTY_RESPONSE response.
This is what I have in my build/web after running flutter build web:
How can I create a local server where I can host my web app locally and run it locally without hosting it on the internet?
as you mentioned in the comment here you go.
Create a file app.js with the following:
const express = require('express')
const app = express()
const port = 8000
app.get('/', (req, res) => {
console.log('getting request')
res.sendFile('website/y.html',{root:__dirname})
})
app.use(express.static(__dirname + '/website'))
app.use((req, res)=>{
res.redirect('/')
})
app.listen(port, () => {
console.log(`app listening at http://localhost:${port}`)
})
Here my website files exist at website folder and my entry point is y.html.
Set the static file directory (your website page) and then serve the .html for the root request
example project: https://github.com/ondbyte/website
Finally, to run it open terminal and move to the root folder. Then do
npm init
npm install express --no-save
node app.js
Here is the more simpler way. NO NEED to setup server
open your Build/web folder in vscode.
install Live server Plugin in vscode.
hit Golive Button
Here you go your flutter web app would be running locally without android studio.

Is Universal link work on HTTP server?

Guys, just want to know whether Universal link can work with HTTP website instead of HTTPS.
If i use universal links in www.mydomain.co.id/match/play_2.html
Entitlement setting is applinks:kumpul.co.id right? But for the apple-app-site-association, i upload it to http://www.mydomain.co.id ,
{
"applinks": {
"apps": [],
"details": [
{
"appID": "[TeamID].id.co.mydomain",
"paths": [ “match/*”]
}
]
}
}
so the location will be http://www.mydomain.co.id/apple-app-site-association. Is it the right configuration ?
3.For debugging information, how could i see my log in iphone when debugging via Xcode to check my code is correct? because when i click links from Whatsapp for example, i can't see the the log in my console
Universal Links URLs can be either http:// or https://. However, the apple-app-site-association file MUST be served over HTTPS otherwise iOS will refuse to scrape it.
This scraping happens only when the app is first installed, and during updates installed from the App Store. Not for every link open. If the scraping attempt fails, you will see an error like this in the OS-level (not App-level in Xcode) logs:
Sep 21 14:27:01 iPhone swcd[2044] <Notice>: 2015-09-21 02:27:01.878907 PM [SWC] ### Rejecting URL 'https://examplecustomdomain.com/apple-app-site-association' for auth method 'NSURLAuthenticationMethodServerTrust': -6754/0xFFFFE59E kAuthenticationErr

Serving Ionic 2 project not working

When running Ionic 2 with the following command,
ionic serve
I get this:
WARN: ionic.config.js has been deprecated, you can remove it.
Running live reload server: http://localhost:35729
Watching: www/**/*, !www/lib/**/*, !www/**/*.map
√ Running dev server: http://localhost:8100
Ionic server commands, enter:
restart or r to restart the client app from the root
goto or g and a url to have the app navigate to the given url
consolelogs or c to enable/disable console log output
serverlogs or s to enable/disable server log output
quit or q to shutdown the server and exit
Here is the ionic config file:
{
"name": "firebaseStart",
"app_id": "",
"v2": true,
"typescript": true
}
How can i run it ?
This is fine. See √ Running dev server: http://localhost:8100
open browser and navigate to
http://localhost:8100

Issues for sending push notification in ionic.io

I created a demo push notification by:
ionic start pushdemo
Add added the following code in app.js:
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
var push = new Ionic.Push({
"debug": true
});
push.register(function(token) {
console.log("Device token:",token.token);
push.saveToken(token);
});
Add I created push certificate and provisioning profile for iOS and also create an app in google for GCM.
Then I set the dev_push to false in .io-config.json.
I tested for Android by running the app in emulator:
ionic run android -lc
Doing this, I can get the device token. Then I'm able to send push notification by curl command:
curl -X POST -H "Authorization: Bearer xxxxeXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI3NjI4MzUyNi1mZjMxLTRhMGItODAxOC0xZmM2ZTY0ZTA3N2YifQ.xCSZk4vQwKajGQ4TOoWyN5GIPnA14jhYfDRMDrtxxxx" -H "Content-Type: application/json" -d '{ "tokens": ["DEV-67e379b0-0752-424c-9a73-0503ce0ad385"], "profile": "pushdemo_dev", "notification": { "message": "Hello World!!!" }}' "https://api.ionic.io/push/notifications"
I have no problem to receive the push notification when the app is running in foreground. But I'm not able to get the push notification when the app is in background.
The other issue is that the device token is always changed when app restart. Is this normal?
Another problem is I'm not able to get push notification when I push message through Dashboard in ionic.io.
Any idea? Thanks.
EDITED:
When I tested on ios device, I'm able to get the device token something like: 5137fcda 88b7e401 2dc7ac21 e4d80f96 d8702ee6 cd6e08ac 874a0b20 9a9882b0. But I can't get push notification when I used the above mentioned curl command. The returned value is:
{"data": {"created": "2016-06-10T09:17:07.031440+00:00", "config":
{"profile": "pushdemo_dev", "notification": {"message": "Hello World
ios!!!"}, "tokens":
["5137fcda88b7e4012dc7ac21e4d80f96d8702ee6cd6e08ac874a0b209a9882b0"]},
"status": "open", "uuid": "151f86f9-8b09-4e9c-9402-779544dbcbd1",
"state": "enqueued", "app_id": "0dfdafd1"}, "meta": {"version":
"2.0.0-beta.0", "request_id": "99e6891c-4fa5-40a9-a1ec-2fd283905c5f",
"status": 201}}
EDIT 2:
Finally get it works in ios by using Postman to push. The format of device token returned is something like 5137fcda 88b7e401 2dc7ac21 e4d80f96 d8702ee6 cd6e08ac 874a0b20 9a9882b0. But when I post in Postman, I have to remove the space. However there is still a problem, I'm not able to receive push notification when I run the app in foreground. It only shows the push notificaiton when the app is running in background.
my program also doent working on real devices but it isworking on browser it means my io is working fine
and for you dont use dashboard instead use postman it is good

Azure Mobile Services / VS Tools for Cordova - 404

I'm trying to get started with Azure Mobile Services and Visual Studio Tools for Apache Cordova. (https://msdn.microsoft.com/en-gb/magazine/dn879353.aspx)
I want to use the Mobile Service for push notifications. I've created the service, with a Node backend, and a TodoItem table. I've got a GCM set up too.
However, when trying to register a template, I get a 404 Not Found error:
var GCM_SENDER_ID = 'MY_GCM_ID';
mobileServiceClient = new WindowsAzure.MobileServiceClient(
"MY_URL",
"MY_API_KEY"
);
pushNotification = PushNotification.init({
"android": { "senderID": GCM_SENDER_ID }
});
pushNotification.on('registration', function (data) {
var handle = data.registrationId; //This appears to be set alright
var platform = device.platform; // This is 'Android'
if (platform == 'android' || platform == 'Android') {
var template = '{ "data" : {"message":"$(message)"}}';
mobileServiceClient.push.gcm.registerTemplate(handle, 'myTemplate', template, null);
});
The final line gives me a 404. I'm running the app in the Google Android Emulator.
EDIT: I tried calling the registrations endpoint using Postman: https://myservice.azure-mobile.net/push/registrations?platform=gcm&deviceId=
If I do a GET, I get [] as a response, if I do a POST, I get 404
Finally fixed it - I didn't have the Cordova Whitelist Plugin installed!
I realised after debugging into MobileServices.Web.js and seeing that the exact same request that was successful with Postman was failing in the Android Emulator.