How to setup a proxy inside Grunt.js based ember-app-kit? - ember.js

I need a proxy to interact with some external APIs during development. I fumbled around with grunt-connect-proxy, but beeing a Grunt noobie, i failed getting it to work inside ember-app-kit's Gruntfile or options/connect.js file.
Assuming that needing a proxy in development would be a rather common task, can somebody show an example of how to setup a proxy inside ember-app-kit?

Assuming you have installed grunt-connect-proxy (npm install grunt-connect-proxy --save-dev)
In Gruntfile.js add 'configureProxies' before 'connect:server' in the test:server and server tasks
grunt.registerTask('server', "Run your server in development mode, auto-rebuilding when files change.",
['build:debug', 'configureProxies', 'connect:server', 'watch:main']);
Add the following to taskRequirements in tasks/helpers.js
'connectProxy': ['grunt-connect-proxy']
In tasks/options/connect.js add the proxy settings on the same level as your server settings
// example settings to proxy to a dev server
proxies: [{
context: '/api',
host: 'localhost',
port: 7000,
changeOrigin: true,
rejectUnauthorized: false
}],
In the same file, add the following to require the proxyRequest in the middleware function
if (Helpers.isPackageAvailable("grunt-connect-proxy")) {
result.splice(1,0, require("grunt-connect-proxy/lib/utils").proxyRequest);
}
See https://gist.github.com/jfranz/7034552 for a more complete example.

Related

deploy nuxtjs application to GCP, but it gives server error?

I'm new to GCP (google cloud platform) I'm facing this problem, Backend dev created an Apache server on gcp, and then I cloned my repo on the server through VM, build it and then deployed it after following countless tutorials.. but while deploying it gives
Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable.
when i go to the generated link which is https://vetution.oa.r.appspot.com/ it gives server error, I've searched a lot but I failed.
Have I done something wrong or the app.yaml file should have different configurations.
anyway here it is
runtime: nodejs12
instance_class: F2
handlers:
- url: /_nuxt
static_dir: .nuxt/dist/client
secure: always
- url: /(.*\.(gif|png|jpg|ico|txt))$
static_files: static/\1
upload: static/.*\.(gif|png|jpg|ico|txt)$
secure: always
- url: /.*
script: auto
secure: always
env_variables:
HOST: '0.0.0.0'
NODE_ENV: 'production'
And It gives me this error on deploying now
please, Help me I'm very frustrated.
The error states that, your app failed to start because it's not listening to a port as you may not have configure it to your app. This topic is answered on this Stackoverflow thread.
You mentioned that you followed countless tutorials, it is possible that you are using Cloud Run and App Engine interchangeably, which are 2 separate serverless products. Please evaluate on your end which platform is right for your app and use case.
Currently, there is not much debugging info to your question but either way, make sure that you configure your app's port to listen to incoming request/s, it can be port 8080 or can be any of your choice. Also, check your GCP logs, backend issues and server errors can be seen and monitored by simply looking at the logs for App Engine or Cloud Run.
Check Cloud Run configuring the container ports, for port configuration.

WebSocket connection to 'ws:/' failed: Error during WebSocket handshake: Unexpected response code: 200

I am using Django-channels to connect to the server, but it always show the error like this:
reconnectwebsockets.js WebSocket connection to 'ws:xxx' failed:
Error during WebSocket handshake: Unexpected response code: 200
Also, I am using docker, this may be a issue of docker container configuration?
Any ideas what could be possibly wrong?
Question details
Hello, did you try to use channels library? It will give you same powerful as Django-channels one. Here you can find necessary documentation for it.
I recommend you use it because it is give you more flexibility then Django-channels one.
Channels library
Quick start
You can read how to work with it at Tutorial.
Errors and solutions
Unexpected response code: 200 (or other code XXX) (solved):
Be sure you include your application and channels via settings (mysite.settings) and use asgi application:
INSTALLED_APPS = [
'channels',
'chat',
...
]
...
ASGI_APPLICATION = "mysite.asgi.application"
Be sure you use channel layers (mysite.settings).
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels.layers.InMemoryChannelLayer',
},
}
According Documentation you should use database for production, but for local environment you may use channels.layers.InMemoryChannelLayer.
Be sure you run asgi server (not wsgi) because you need asynchronous behaviour. Also, for deployment you should use daphne instead of gunicorn. daphne is included in channels library by default, so you don't need to install it manually.
Basic run server will look like (Terminal):
daphne -b 0.0.0.0 -p $PORT mysite.asgi:application
where $PORT is specific port (for UNIX system is 5000). (That format used for heroku application, you can change it manually).
Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR and same errors with using https connection (solved):
Difference between ws and wss?
You may think about to use your server via wss protocol:
replace ws://... with wss://... or use following template in your html (chat/templates/chat/room.html):
(window.location.protocol === 'https:' ? 'wss' : 'ws') + '://'
Hope this answer is useful for channels with Django.

RuntimeException: E_MISSING_CONFIG Adonis.js

Getting the following error while running the app:
RuntimeException: E_MISSING_CONFIG: logger.transport is not defined inside config/app.js file
Below is the config/app.js file with logger config code (comments have been removed),
logger: {
transport: 'console',
console: {
driver: 'console',
name: 'adonis-app',
level: 'info'
},
file: {
driver: 'file',
name: 'adonis-app',
filename: 'adonis.log',
level: 'info'
}
}
I am still new to adonis and couldn't think of possible issue with this configurations.
Dependencies:
"#adonisjs/ace": "^5.0.1",
"#adonisjs/antl": "^2.0.5",
"#adonisjs/auth": "^3.0.4",
"#adonisjs/bodyparser": "^2.0.2",
"#adonisjs/cors": "^1.0.5",
"#adonisjs/drive": "^1.0.2",
"#adonisjs/fold": "^4.0.7",
"#adonisjs/framework": "^5.0.5",
"#adonisjs/ignitor": "^2.0.8",
"#adonisjs/lucid": "^5.0.3",
"#adonisjs/mail": "^3.0.7",
"#adonisjs/session": "^1.0.23",
"#adonisjs/shield": "^1.0.6",
"#adonisjs/validator": "^5.0.3",
"acler": "^1.0.0",
"adonis-acl": "^1.1.0",
"adonis-scheduler": "^3.0.2",
I know this is has been asked a while ago, but I came across the same issue and couldn't find an answer anywhere.
Anyways, turned out it was caused by HTTPS in my case. For some reason when you run the server in HTTPS mode(as described in their docs) it can no longer run your app/tests if it can't find the SSL key and cert files.
On production this doesn't matter cause it'll be able to find the SSL files, but in my case I was using this with gitlab CI to run tests before deploying it to my remote host. the gitlab CI runner doesn't have the SSL files and thus couldn't run the tests.
I've solved this issue by simply copying server.js to server-ssl.js and making sure I run server.js when testing, and server-ssl.js on my remote host.
server.js contains the default HTTP server configuration, and server-ssl.js contains the HTTPS server configuration.
Hope this helps someone out in the future! ;)
EDIT: This error can also occur when you're trying to load a config option that doesn't exist in any other config file. eg reading from a file that doesn't exist(fs.readFileSync).

Angular8: Call localhost Rest Api services

I developed my web application with Angular 8. The backend is a rest api that I developed with django rest framework and it's viewed just in the localhost. I tested it and it works fine. For example the service http://127.0.0.1:8000/api/devices gives a list of devices. It gives a good results if I test it with browser or curl command.
I'm calling this service from my angular app. I executed the angular app with the command: ng serve --host 0.0.0.0 --port 4201
If I open the web application in the browser with http://127.0.0.1:4201/api/devices the service /api/devices is well called and I get the list of devices in my web page. but if I open the web application with my LAN IP address like that http://192.168.1.59:4201/api/devices, so I get HTTP 400 bad request error in my console.
And the same error is shown in django server traces: GET /api/devices/ HTTP/1.1" 400 26
After some searches in the internet I concluded that this error is frequently coming from angular app especially the proxy:
my proxy config file proxy.config.json is:
{
"/api" : {
"target": "http://localhost:8000",
"secure": false
}
}
I mad other searches and I found an answer to similar question Angular 6 call localhost API and after following the angular doc https://angular.io/guide/build in "Proxying to a backend server" section then I modified my proxy config file to:
{
"/api": {
"target": "http://localhost:8000",
"secure": false,
"pathRewrite": {
"^/api": ""
}
}
}
Has any one an idea what can be the main cause of the issue? and how I can fix it?
ng serve --host 0.0.0.0 --port 4201 --disable-host-check

Meteor UP : Verifying development failed

Im getting following error when trying to deploy my meteor application in AWS.
I have selected ubuntu as my operating system with 30 Gb of HDD. i have attached my mup.json file and snap of cmd response .
My mup.json is :
{
// Server authentication info
"servers": [
{
"host": "ec2-XXXXXXXXXXXXXXXXXXXXXXXXXXXXX.compute.amazonaws.com",
"username": "ubuntu",
//"password": "password"
// or pem file (ssh based authentication)
"pem": "D:/abcUbuntu.pem"
}
],
// Install MongoDB in the server, does not destroy local MongoDB on future setup
"setupMongo": true,
// WARNING: Node.js is required! Only skip if you already have Node.js installed on server.
"setupNode": true,
// WARNING: If nodeVersion omitted will setup 0.10.36 by default. Do not use v, only version number.
"nodeVersion": "0.10.36",
// Install PhantomJS in the server
"setupPhantom": true,
// Show a progress bar during the upload of the bundle to the server.
// Might cause an error in some rare cases if set to true, for instance in Shippable CI
"enableUploadProgressBar": true,
// Application name (No spaces)
"appName": "Qxmedics",
// Location of app (local directory)
"app": "D:/abc/version1",
// Configure environment
"env": {
"PORT":80,
"ROOT_URL": "ec2-XXXXXXXXXXXXXXXXXXXXX.compute.amazonaws.com",
"MONGO_URL": "mongodb://localhost:27017/meteor"
},
// Meteor Up checks if the app comes online just after the deployment
// before mup checks that, it will wait for no. of seconds configured below
"deployCheckWaitTime": 15
}
I tried alot... please help me out with this thanks.
For me the solution was making the wait time 45. If the rest is correct, it should confirm and deploy.
"deployCheckWaitTime": 45
It says there is a problem with your URL so, make sure it is a correct one with http or https.