Unable to deploy on Heroku - heroku

I developed a front end app an I am unable to deploy it on heroku it is saying buildpack not found can anyone help.
this is the url to my repository
https://github.com/DashingAssassin/OnePush

Most of cases Heroku is used to deploy, run and manage applications written in Ruby, Node.js, Java, Python, Clojure, Scala, Go and PHP.
To push front end applications bitballon provides easiest way.(you can just Drag/Drop your project files(which should has index files) over there)
https://www.bitballoon.com
I have used this to host an angular application.(As similar to your git repository which is hacker earth hiring challenge)
sample angular with bitballon(Front end app)
OR
USE Heroku
Install Heroku cli in your PC
create nodeJS app heroku portal.
Create app folder copy all front-end app files into that
4.place Server ServerJS in beside app folder.
heroku login, heroku git:clone -a $APPNAME, git add and git commit.
Finally git push heroku master
--> Server JS :
var express = require("express");
var port = process.env.PORT || 8080;
var app = express();
app.use(function(req, res, next) {
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
res.setHeader('Access-Control-Allow-Credentials', true);
next();
});
var router = express.Router();
app.use('/', router);
app.use(express.static(__dirname + '/app'));
app.listen(port);
console.log('---------------------------------- ');
console.log('Server Started on port: ' + port);
console.log('---------------------------------- ');
Package.json
{
"name": "node-api",
"main": "server.js",
"dependencies": {
"express": "^4.14.0"
}
}

Related

Error during Websocket handshake with error code 500 using Daphne on Heroku

So I tried to deploy my docker django chat app to heroku. Previously I had been running the app with runserver command, but now I'm switching to daphne since I need to use websocket but I can't use runserver anymore in order to connect to webserver. After deployment, when I access the app page that shows the chat window this error occurs
WebSocket connection to 'wss://xxx.herokuapp.com/ws/chat/room/' failed: Error during WebSocket handshake: Unexpected response code: 500
(xxx is actually the url of my app)
Here's a piece of my js code
<script>
var roomName = "{{ room_name|escapejs }}";
var wsStart = 'ws://';
if (window.location.protocol === 'https:') {
wsStart = 'wss://';
}
var chatSocket = new WebSocket(
wsStart + window.location.host +
'/ws/chat/' + roomName + '/');
chatSocket.onmessage = function(e) {
var data = JSON.parse(e.data);
var message = data['message'];
document.querySelector('#chat-log').value += (message + '\n');
};
ws didn't work (error message Django can only use ASGI not websocket) so I changed to wss (according to another post in stackoverflow it's because security reason), which made the other error go away but still can't connect to websocket
This is my run command:
daphne -p $PORT --bind 0.0.0.0 -v2 test_project.asgi:application
EDIT: if I don't use wss (just use ws instead) this is the error message in js console
The page at 'https://xxx/chat/m/' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://xxx/ws/chat/room/'. This request has been blocked; this endpoint must be available over WSS.
Extremely appreciate any help, or ideas of what went wrong. Thank you so much!
Turns out it has just about nothing to do with daphne or my js code that doesn't work. I didn't connect to a heroku-redis at the time and thus was not running redis. Configured REDISTOGO_URL with
heroku config --app <appname> | grep REDISTOGO_URL
, changed host in channel_layer from "hosts": ('redis', 6379), (something similar) to "hosts": [os.environ.get('REDISTOGO_URL',('redis', 6379))] allowed me to connect to heroku redis.

Can't get proxying a websocket working with create-react-app

I created a CRA in a docker container and I'm trying to proxy websockets over to another container running a python backend. I for the life of me cannot get the connection working.
I have verified that the server works by exposing the port outside of docker and connecting to it from the browser directly - it connects and works.
I can also verify that the connection within my CRA docker is set up properly - within it I start up a shell and do
> WS = require('ws')
> new WS(`ws://server:8765/ws/foo`).addEventListener('open', e => console.log('open'))
and that connects and prints open too. (This is why I don't have the docker tag on here, from my understanding this eliminates docker from being a possible issue since I've confirmed I can connect from one to the other)
The only thing that I can think of is that the proxy configuration is wrong
Here's what I'm trying to do on the client
const socket = new WebSocket(`ws:localhost/ws/foo`)
my proxy setup
const proxy = require("http-proxy-middleware")
module.exports = (app) => {
as I can tell. Need to circle back
app.use(`/ws*`, proxy({
target: 'ws://server:8765/ws',
changeOrigin: true,
ws: true,
}))
}
I have tried that with /ws and with putting the url in the proxy clause instead o the use and...still nothing
I'm really not sure what more I can be missing.
Here are my dependency versions
"dependencies": {
"#reach/router": "^1.2.1",
"http-proxy-middleware": "^0.20.0",
"react": "^16.10.2",
"react-dom": "^16.10.2",
"react-scripts": "3.2.0",
"styled-components": "^4.4.0"
},

proxy.conf.json is not working in angular 6 when i use ng build

I am trying to create a project using proxy to connect to the backend, but when generating the project with ng build, the proxy configuration does not work as it does with ng serve.
To generate use the following command:
ng build --prod --base-href = / myproyect /
Next I pass the files that I have of configuration:
proxy.conf.json:
{
"/api/*": {
"target": "http://localhost:8080/cystock/",
"secure": false,
"pathRewrite": {"^/api" : ""},
"changeOrigin": true,
"logLevel": "debug"
}
}
global.ts:
export const GLOBAL = {
production: true,
url: 'api'//<-- 'API/' prefix needed for proxy configuration
};
Note: The idea is to be able to consume localhost services, which is developed with JAVA using Spring as framework
As #vikas said, the proxy-config is strictly for development. It makes it easy to "mock" your endpoints while you're developing your application without the need for multiple configuration files.
The idea with proxy-config is that you proxy your production URL to a dev server (remote or local), and when you build your code without the proxy, it points to your production server.
To solve your issue specifically, just change /api to your production endpoint, and map it to a development server.

How can I deploy beego app to Heroku

I'm creating a web app in beego that I need to have running in Heroku.
I can get it running normally if I just specify the binary for the app in the Procfile. But I want to have swagger available in the app, so I need to use bee to start the app like:
bee run -downdoc=true -gendoc=true
so that it automatically creates and downloads all the swagger related icons, html, etc.
But, if I specify that as the command in Procfile (even after adding bee to vendor so that it is available), it fails because the app doesn't have the go command available in runtime. The exact error is this:
0001 There was an error running 'go version' command: exec: "go": executable file not found in $PATH
How can I bypass this without adding the whole swagger specification to heroku (and github, since it is a repository)?
You can not run bee command on heroku, because it is a executable program.
But you can run beego app on heroku with adding project dependencies. In order to that you should use tools like https://github.com/kardianos/govendor.
1. After install govendor try following steps in your project folder;
$ govendor init
This command will create ./vendor/vendor.json file in current directory.
{
"comment": "https://github.com/ismailakbudak/beego-api-example",
"heroku": {
"install" : [ "./..." ],
"goVersion": "go1.11"
},
"ignore": "test",
"package": [],
"rootPath": "reporting-api"
}
Add heroku tag like above example. There is a information about this configuration on heroku docs in here https://devcenter.heroku.com/articles/go-dependencies-via-govendor#build-configuration
2. After this add beego package dependency with this command
$ govendor fetch github.com/astaxie/beego
It will download the beego packages to ./vendor directory
3. Lastly you should configure listen ports and beego runmode as prod for heroku in main.go file
To deploy your app without problem, default config must be runmode = prod in conf/app.conf. I tried to set it default as dev and change it from heroku config vars as below, but it compiles packages before the set runmode and gives exception with this message panic: you are running in dev mode.
func main() {
log.Println("Env $PORT :", os.Getenv("PORT"))
if os.Getenv("PORT") != "" {
port, err := strconv.Atoi(os.Getenv("PORT"))
if err != nil {
log.Fatal(err)
log.Fatal("$PORT must be set")
}
log.Println("port : ", port)
beego.BConfig.Listen.HTTPPort = port
beego.BConfig.Listen.HTTPSPort = port
}
if os.Getenv("BEEGO_ENV") != "" {
log.Println("Env $BEEGO_ENV :", os.Getenv("BEEGO_ENV"))
beego.BConfig.RunMode = os.Getenv("BEEGO_ENV")
}
beego.BConfig.WebConfig.DirectoryIndex = true
beego.BConfig.WebConfig.StaticDir["/"] = "swagger"
beego.Run()
}
You can use BEEGO_ENV=dev bee run to continue develop your app without change it again

meanjs best practice to setup process evn for database

In my attempt to get a 'hello world' skill with meanjs.org product, I cloned 0.4.2 and setup a mongolab account.
I opened > config > env > development.js, to setup db URL, where I have this:
db: {
uri: process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://' + (process.env.DB_1_PORT_27017_TCP_ADDR || 'localhost') + '/mean-dev',
For trial, I simply replaced process.env.MONGOLAB_URI with my URL from mongolab and everthing worked for sure, but I doubt this is the way to go. I see a Procfile there, may be I should specify the process.env.MONGOLAB_URI there? Where I could specify it, so that if I upload it to Heroku, say, it will setup the process.env.MONGOLAB_URI and no edit will be needed here please?
p.s. I googled and searched SOF
Well just a small progress,
I got to my gulpfile.js and setup a task as:
gulp.task('setmydb', function () {
process.env.MONGOLAB_URI =
'mongodb://mylogin:mypassword#ds157479.mlab.com:57479/meantst1';
});
Then at the end of the file, added into the task sequence:
// Run the project in development mode
gulp.task('default', function (done) {
runSequence('env:dev', 'lint', ['setmydb','nodemon', 'watch'], done);
});
Well it worked, but I'm still not sure if this indeed is how it must be done! So please help me get sure.
Just in case if someone else also needed, this is how I solved my problem:
Setting configuration variables | Heroku
I first followed the Heroku getting started and edited their app there, added this root:
app.get('/envtst', function(request, response) {
var xterm = process.env.XVAR ==='yes' ? 'yes' : 'no';
response.send(xterm);
});
Then pushed the app to Heroku and also setup my test variable XVAR via command line:
heroku config:set XVAR=yes
finally, opened the root in browser and verified.

Resources