I have an app deployed on heroku. My production and dev environments both use PostgreSQL and I use knex for my database querying. I am getting an issue where no resources load onto a page and heroku log --tail says this:
2022-08-23T21:34:19.565970+00:00 app[web.1]: There is an error here: select *, "authors"."name" as "author_name", "authors"."id" as "author_id" from "books" inner join "authors" on "books"."author_id" = "authors"."id" where "books"."id" = $1 limit $2 - column books.author_id does not exist
However, the call works fine on localhost - I have checked my database schema on pgadmin and it appears that the column does exist.
Here is the call to the database:
function getBookById(id) {
console.log(id)
return db('books')
.join('authors', 'books.author_id', 'authors.id')
.where('books.id', id)
.select('*', 'authors.name as author_name', 'authors.id as author_id')
.first()
}
I have done a bit more diving in and looks like it is breaking on a number of database hits and returning 503s.
Here is some more error messages I am getting when I run heroku log --tail
2022-08-24T02:25:36.434109+00:00 app[web.1]: at Parser.parseErrorMessage (/app/node_modules/pg-protocol/dist/parser.js:287:98)
2022-08-24T02:25:36.434109+00:00 app[web.1]: at Parser.handlePacket (/app/node_modules/pg-protocol/dist/parser.js:126:29)
2022-08-24T02:25:36.434110+00:00 app[web.1]: at Parser.parse (/app/node_modules/pg-protocol/dist/parser.js:39:38)
2022-08-24T02:25:36.434110+00:00 app[web.1]: at TLSSocket.<anonymous> (/app/node_modules/pg-protocol/dist/index.js:11:42)
2022-08-24T02:25:36.434111+00:00 app[web.1]: at TLSSocket.emit (node:events:513:28)
2022-08-24T02:25:36.434112+00:00 app[web.1]: at addChunk (node:internal/streams/readable:315:12)
2022-08-24T02:25:36.434112+00:00 app[web.1]: at readableAddChunk (node:internal/streams/readable:289:9)
2022-08-24T02:25:36.434112+00:00 app[web.1]: at TLSSocket.Readable.push (node:internal/streams/readable:228:10)
2022-08-24T02:25:36.434113+00:00 app[web.1]: at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23) {
2022-08-24T02:25:36.434113+00:00 app[web.1]: length: 127,
2022-08-24T02:25:36.434114+00:00 app[web.1]: severity: 'ERROR',
2022-08-24T02:25:36.434114+00:00 app[web.1]: code: '42703',
2022-08-24T02:25:36.434114+00:00 app[web.1]: detail: undefined,
2022-08-24T02:25:36.434115+00:00 app[web.1]: hint: undefined,
2022-08-24T02:25:36.434115+00:00 app[web.1]: position: '22',
2022-08-24T02:25:36.434115+00:00 app[web.1]: internalPosition: undefined,
2022-08-24T02:25:36.434115+00:00 app[web.1]: internalQuery: undefined,
2022-08-24T02:25:36.434116+00:00 app[web.1]: where: undefined,
2022-08-24T02:25:36.434116+00:00 app[web.1]: schema: undefined,
2022-08-24T02:25:36.434116+00:00 app[web.1]: table: undefined,
2022-08-24T02:25:36.434116+00:00 app[web.1]: column: undefined,
2022-08-24T02:25:36.434117+00:00 app[web.1]: dataType: undefined,
2022-08-24T02:25:36.434117+00:00 app[web.1]: constraint: undefined,
2022-08-24T02:25:36.434117+00:00 app[web.1]: file: 'parse_target.c',
2022-08-24T02:25:36.434118+00:00 app[web.1]: line: '1061',
2022-08-24T02:25:36.434118+00:00 app[web.1]: routine: 'checkInsertTargets'
2022-08-24T02:25:36.434118+00:00 app[web.1]: }
2022-08-24T02:25:36.434240+00:00 app[web.1]: There is an error here: insert into "books" ("author_id", "blurb", "cover_image", "genre", "pub_year", "title") values ($1, $2, $3, $4, $5, $6) returning "id" - column "author_id" of relation "books" does not exist
I'm not sure if this is something weird with heroku's postgres - or something I'm doing wrong (more likely). It is unclear to me how to further trouble shoot this issue.
Thanks for an help
I am trying to deploy my app to Heroku. Heroku provides a DATABASE_URL environment variable. I am wondering what is the best way to use this.
When in dev the DATABASE_URL environment variable will be jdbc:postgresql://localhost:5400/bookswapdb
When in prd the DATABASE_URL environment variable will be something like this: postgres://<USER>:<PASSWORD>#<HOST>:<PORT>/<DATABASE>
Is checking the DATABASE_URL really the best way to discover whether the app is in prod or dev? (I would have thought they would also pass in a variable like ENV=prd or PRD=true)
Given the code below, what is the smartest way to achieve checking the DATABASE_URL and passing it into initFlyway function.
What's the cleanest way to chop up this string to get the details i need postgres://<USER>:<PASSWORD>#<HOST>:<PORT>/<DATABASE>
The DATABASE_URL might be in this format: jdbc:postgresql://<host>:<port>/<dbname>?user=<username>&password=<password> if so how is the best way to divide that?
The below doesn't seem to work when deployed to heroku but it does work on a local db.
package com.fullstackryan.appone.server
import cats.effect.{ConcurrentEffect, ContextShift, Sync, Timer}
import cats.implicits._
import com.fullstackryan.appone.config.{Config, DbConfig, LoadConfig, ServerConfig}
import com.fullstackryan.appone.database.Database
import com.fullstackryan.appone.repo.{BookSwap, HelloWorld, Jokes}
import com.fullstackryan.appone.routing.ApponeRoutes
import fs2.Stream
import org.flywaydb.core.Flyway
import org.http4s.client.blaze.BlazeClientBuilder
import org.http4s.implicits._
import org.http4s.server.blaze.BlazeServerBuilder
import org.http4s.server.middleware.Logger
import pureconfig.generic.auto._
import java.net.URI
import scala.concurrent.ExecutionContext.global
object ApponeServer {
def initFlyway[F[_] : Sync](url: String, username: String, password: String): F[Int] = Sync[F].delay {
val flyway = Flyway.configure().dataSource(url, username, password).baselineOnMigrate(true).load()
println("inside flyway")
flyway.migrate()
}
def prodConfig(): Config = {
val dbUri = new URI(System.getenv("DATABASE_URL"))
val username = dbUri.getUserInfo.split(":")(0)
val password = dbUri.getUserInfo.split(":")(1)
val dbUrl = "jdbc:postgresql://" + dbUri.getHost + dbUri.getPath
Config(ServerConfig(5432, dbUri.getHost), DbConfig(dbUrl, username, password, 10))
}
def stream[F[_] : ConcurrentEffect : ContextShift : Timer]: Stream[F, Nothing] = {
for {
client <- BlazeClientBuilder[F](global).stream
// below line loads config from application.conf
config <- Stream.eval(LoadConfig[F, Config].load)
// This is meant to check if DATABASE_URL is dev or prd
isProdConfig = if (config.dbConfig.url.contains("localhost")) config else prodConfig()
// Below line hopefully passes correct prd or dev config into initFlyway to get a connnection
_ <- Stream.eval(initFlyway(isProdConfig.dbConfig.url, isProdConfig.dbConfig.username, isProdConfig.dbConfig.password))
xa <- Stream.resource(Database.transactor(isProdConfig.dbConfig))
helloWorldAlg = HelloWorld.impl[F]
jokeAlg = Jokes.impl[F](client)
bookAlg = BookSwap.buildInstance[F](xa)
httpApp = (
ApponeRoutes.helloWorldRoutes[F](helloWorldAlg) <+>
ApponeRoutes.bookRoutes[F](bookAlg) <+>
ApponeRoutes.jokeRoutes[F](jokeAlg)
).orNotFound
finalHttpApp = Logger.httpApp(true, true)(httpApp)
exitCode <- BlazeServerBuilder[F](global)
.bindHttp(8080, "0.0.0.0")
.withHttpApp(finalHttpApp)
.serve
} yield exitCode
}.drain
}
ERROR
2021-01-17T14:05:29.437876+00:00 heroku[web.1]: State changed from crashed to starting
2021-01-17T14:05:35.808791+00:00 heroku[web.1]: Starting process with command `target/universal/stage/bin/appone -Dhttp.port=${PORT}`
2021-01-17T14:05:39.711887+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2021-01-17T14:05:40.047036+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2021-01-17T14:05:48.838694+00:00 app[web.1]: [ioapp-compute-0] INFO o.h.c.PoolManager - Shutting down connection pool: curAllocated=0 idleQueues.size=0 waitQueue.size=0 maxWaitQueueLimit=256 closed=false
2021-01-17T14:05:48.972995+00:00 app[web.1]: pureconfig.error.ConfigReaderException: Cannot convert configuration to a scala.runtime.Nothing$. Failures are:
2021-01-17T14:05:48.973019+00:00 app[web.1]: at 'appone.db-config':
2021-01-17T14:05:48.973021+00:00 app[web.1]: - (application.conf # jar:file:/app/target/universal/stage/lib/com.fullstackryan.appone-0.0.1-SNAPSHOT.jar!/application.conf: 10) Key not found: 'username'.
2021-01-17T14:05:48.973022+00:00 app[web.1]: - (application.conf # jar:file:/app/target/universal/stage/lib/com.fullstackryan.appone-0.0.1-SNAPSHOT.jar!/application.conf: 10) Key not found: 'password'.
2021-01-17T14:05:48.977706+00:00 app[web.1]:
2021-01-17T14:05:48.977988+00:00 app[web.1]: at com.fullstackryan.appone.config.LoadConfig$$anon$1.$anonfun$load$1(LoadConfig.scala:25)
2021-01-17T14:05:48.978182+00:00 app[web.1]: at cats.syntax.EitherOps$.leftMap$extension(either.scala:172)
2021-01-17T14:05:48.992062+00:00 app[web.1]: at com.fullstackryan.appone.config.LoadConfig$$anon$1.load(LoadConfig.scala:25)
2021-01-17T14:05:48.992224+00:00 app[web.1]: at com.fullstackryan.appone.server.ApponeServer$.$anonfun$stream$1(ApponeServer.scala:50)
2021-01-17T14:05:48.992352+00:00 app[web.1]: at com.fullstackryan.appone.server.ApponeServer$.$anonfun$stream$1$adapted(ApponeServer.scala:48)
2021-01-17T14:05:48.992496+00:00 app[web.1]: at fs2.Stream$.$anonfun$flatMap$1(Stream.scala:1188)
2021-01-17T14:05:48.992649+00:00 app[web.1]: at fs2.internal.FreeC$.go$2(Algebra.scala:609)
2021-01-17T14:05:48.992861+00:00 app[web.1]: at fs2.internal.FreeC$.$anonfun$flatMapOutput$1(Algebra.scala:616)
2021-01-17T14:05:48.993129+00:00 app[web.1]: at fs2.internal.FreeC$$anon$1.cont(Algebra.scala:53)
2021-01-17T14:05:48.996922+00:00 app[web.1]: at fs2.internal.FreeC$ViewL$$anon$9$$anon$10.cont(Algebra.scala:242)
2021-01-17T14:05:48.997120+00:00 app[web.1]: at fs2.internal.FreeC$ViewL$.mk(Algebra.scala:231)
2021-01-17T14:05:48.997247+00:00 app[web.1]: at fs2.internal.FreeC$ViewL$.apply(Algebra.scala:220)
2021-01-17T14:05:48.997395+00:00 app[web.1]: at fs2.internal.FreeC.viewL(Algebra.scala:106)
2021-01-17T14:05:48.997537+00:00 app[web.1]: at fs2.internal.FreeC$.go$1(Algebra.scala:414)
2021-01-17T14:05:48.997707+00:00 app[web.1]: at fs2.internal.FreeC$.$anonfun$compile$8(Algebra.scala:464)
2021-01-17T14:05:48.998481+00:00 app[web.1]: at fs2.internal.FreeC$.$anonfun$compile$1(Algebra.scala:430)
2021-01-17T14:05:48.998648+00:00 app[web.1]: at map # fs2.internal.CompileScope.interruptibleEval(CompileScope.scala:393)
2021-01-17T14:05:48.998778+00:00 app[web.1]: at flatMap # fs2.internal.FreeC$.go$1(Algebra.scala:490)
2021-01-17T14:05:48.998907+00:00 app[web.1]: at flatMap # fs2.internal.FreeC$.$anonfun$compile$5(Algebra.scala:450)
2021-01-17T14:05:48.999061+00:00 app[web.1]: at flatMap # fs2.internal.FreeC$.go$1(Algebra.scala:447)
2021-01-17T14:05:48.999202+00:00 app[web.1]: at flatMap # fs2.internal.FreeC$.interruptGuard$1(Algebra.scala:429)
2021-01-17T14:05:48.999348+00:00 app[web.1]: at flatMap # fs2.internal.FreeC$.interruptGuard$1(Algebra.scala:429)
2021-01-17T14:05:49.000021+00:00 app[web.1]: at flatMap # fs2.internal.CompileScope.$anonfun$acquireResource$4(CompileScope.scala:185)
2021-01-17T14:05:49.000182+00:00 app[web.1]: at flatten # fs2.internal.ScopedResource$$anon$1.acquired(ScopedResource.scala:139)
2021-01-17T14:05:49.000285+00:00 app[web.1]: at flatMap # fs2.internal.CompileScope.$anonfun$acquireResource$1(CompileScope.scala:183)
2021-01-17T14:05:49.000409+00:00 app[web.1]: at flatMap # fs2.internal.CompileScope.acquireResource(CompileScope.scala:180)
2021-01-17T14:05:49.000547+00:00 app[web.1]: at flatMap # fs2.internal.FreeC$.$anonfun$compile$10(Algebra.scala:498)
2021-01-17T14:05:49.000665+00:00 app[web.1]: at flatMap # fs2.internal.FreeC$.interruptGuard$1(Algebra.scala:429)
2021-01-17T14:05:49.000782+00:00 app[web.1]: at flatMap # fs2.internal.FreeC$.interruptGuard$1(Algebra.scala:429)
2021-01-17T14:05:49.000911+00:00 app[web.1]: at flatMap # fs2.internal.FreeC$.interruptGuard$1(Algebra.scala:429)
2021-01-17T14:05:49.001062+00:00 app[web.1]: at flatMap # fs2.internal.CompileScope.$anonfun$acquireResource$4(CompileScope.scala:185)
2021-01-17T14:05:49.001165+00:00 app[web.1]: at flatten # fs2.internal.ScopedResource$$anon$1.acquired(ScopedResource.scala:139)
2021-01-17T14:05:49.171354+00:00 heroku[web.1]: Process exited with status 1
2021-01-17T14:05:49.208726+00:00 heroku[web.1]: State changed from starting to crashed
2021-01-17T14:05:49.211138+00:00 heroku[web.1]: State changed from crashed to starting
2021-01-17T14:05:55.214070+00:00 heroku[web.1]: Starting process with command `target/universal/stage/bin/appone -Dhttp.port=${PORT}`
2021-01-17T14:05:58.596071+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2021-01-17T14:05:58.994577+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2021-01-17T14:05:59.000000+00:00 app[api]: Build succeeded
2021-01-17T14:06:04.235862+00:00 app[web.1]: [ioapp-compute-0] INFO o.h.c.PoolManager - Shutting down connection pool: curAllocated=0 idleQueues.size=0 waitQueue.size=0 maxWaitQueueLimit=256 closed=false
2021-01-17T14:06:04.319171+00:00 app[web.1]: pureconfig.error.ConfigReaderException: Cannot convert configuration to a scala.runtime.Nothing$. Failures are:
2021-01-17T14:06:04.319174+00:00 app[web.1]: at 'appone.db-config':
2021-01-17T14:06:04.319195+00:00 app[web.1]: - (application.conf # jar:file:/app/target/universal/stage/lib/com.fullstackryan.appone-0.0.1-SNAPSHOT.jar!/application.conf: 10) Key not found: 'username'.
2021-01-17T14:06:04.319196+00:00 app[web.1]: - (application.conf # jar:file:/app/target/universal/stage/lib/com.fullstackryan.appone-0.0.1-SNAPSHOT.jar!/application.conf: 10) Key not found: 'password'.
2021-01-17T14:06:04.319206+00:00 app[web.1]:
2021-01-17T14:06:04.319341+00:00 app[web.1]: at com.fullstackryan.appone.config.LoadConfig$$anon$1.$anonfun$load$1(LoadConfig.scala:25)
2021-01-17T14:06:04.319403+00:00 app[web.1]: at cats.syntax.EitherOps$.leftMap$extension(either.scala:172)
2021-01-17T14:06:04.319496+00:00 app[web.1]: at com.fullstackryan.appone.config.LoadConfig$$anon$1.load(LoadConfig.scala:25)
2021-01-17T14:06:04.319683+00:00 app[web.1]: at com.fullstackryan.appone.server.ApponeServer$.$anonfun$stream$1(ApponeServer.scala:50)
2021-01-17T14:06:04.319688+00:00 app[web.1]: at com.fullstackryan.appone.server.ApponeServer$.$anonfun$stream$1$adapted(ApponeServer.scala:48)
2021-01-17T14:06:04.319785+00:00 app[web.1]: at fs2.Stream$.$anonfun$flatMap$1(Stream.scala:1188)
2021-01-17T14:06:04.319847+00:00 app[web.1]: at fs2.internal.FreeC$.go$2(Algebra.scala:609)
2021-01-17T14:06:04.319951+00:00 app[web.1]: at fs2.internal.FreeC$.$anonfun$flatMapOutput$1(Algebra.scala:616)
2021-01-17T14:06:04.320042+00:00 app[web.1]: at fs2.internal.FreeC$$anon$1.cont(Algebra.scala:53)
2021-01-17T14:06:04.320188+00:00 app[web.1]: at fs2.internal.FreeC$ViewL$$anon$9$$anon$10.cont(Algebra.scala:242)
2021-01-17T14:06:04.320257+00:00 app[web.1]: at fs2.internal.FreeC$ViewL$.mk(Algebra.scala:231)
2021-01-17T14:06:04.320336+00:00 app[web.1]: at fs2.internal.FreeC$ViewL$.apply(Algebra.scala:220)
2021-01-17T14:06:04.320405+00:00 app[web.1]: at fs2.internal.FreeC.viewL(Algebra.scala:106)
2021-01-17T14:06:04.320481+00:00 app[web.1]: at fs2.internal.FreeC$.go$1(Algebra.scala:414)
2021-01-17T14:06:04.320561+00:00 app[web.1]: at fs2.internal.FreeC$.$anonfun$compile$8(Algebra.scala:464)
2021-01-17T14:06:04.320641+00:00 app[web.1]: at fs2.internal.FreeC$.$anonfun$compile$1(Algebra.scala:430)
2021-01-17T14:06:04.320719+00:00 app[web.1]: at map # fs2.internal.CompileScope.interruptibleEval(CompileScope.scala:393)
2021-01-17T14:06:04.320785+00:00 app[web.1]: at flatMap # fs2.internal.FreeC$.go$1(Algebra.scala:490)
2021-01-17T14:06:04.320862+00:00 app[web.1]: at flatMap # fs2.internal.FreeC$.$anonfun$compile$5(Algebra.scala:450)
2021-01-17T14:06:04.320929+00:00 app[web.1]: at flatMap # fs2.internal.FreeC$.go$1(Algebra.scala:447)
2021-01-17T14:06:04.320995+00:00 app[web.1]: at flatMap # fs2.internal.FreeC$.interruptGuard$1(Algebra.scala:429)
2021-01-17T14:06:04.321076+00:00 app[web.1]: at flatMap # fs2.internal.FreeC$.interruptGuard$1(Algebra.scala:429)
2021-01-17T14:06:04.321138+00:00 app[web.1]: at flatMap # fs2.internal.CompileScope.$anonfun$acquireResource$4(CompileScope.scala:185)
2021-01-17T14:06:04.321230+00:00 app[web.1]: at flatten # fs2.internal.ScopedResource$$anon$1.acquired(ScopedResource.scala:139)
2021-01-17T14:06:04.321289+00:00 app[web.1]: at flatMap # fs2.internal.CompileScope.$anonfun$acquireResource$1(CompileScope.scala:183)
2021-01-17T14:06:04.321385+00:00 app[web.1]: at flatMap # fs2.internal.CompileScope.acquireResource(CompileScope.scala:180)
2021-01-17T14:06:04.321473+00:00 app[web.1]: at flatMap # fs2.internal.FreeC$.$anonfun$compile$10(Algebra.scala:498)
2021-01-17T14:06:04.321531+00:00 app[web.1]: at flatMap # fs2.internal.FreeC$.interruptGuard$1(Algebra.scala:429)
2021-01-17T14:06:04.321607+00:00 app[web.1]: at flatMap # fs2.internal.FreeC$.interruptGuard$1(Algebra.scala:429)
2021-01-17T14:06:04.321668+00:00 app[web.1]: at flatMap # fs2.internal.FreeC$.interruptGuard$1(Algebra.scala:429)
2021-01-17T14:06:04.321779+00:00 app[web.1]: at flatMap # fs2.internal.CompileScope.$anonfun$acquireResource$4(CompileScope.scala:185)
2021-01-17T14:06:04.321811+00:00 app[web.1]: at flatten # fs2.internal.ScopedResource$$anon$1.acquired(ScopedResource.scala:139)
2021-01-17T14:06:04.453054+00:00 heroku[web.1]: Process exited with status 1
2021-01-17T14:06:04.497636+00:00 heroku[web.1]: State changed from starting to crashed
2021-01-17T14:28:36.868097+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=appone2021.herokuapp.com request_id=a2e9c2cb-9e29-4e90-a528-2b93822a5b22 fwd="2.221.116.154" dyno= connect= service= status=503 bytes= protocol=https
2021-01-17T14:28:37.225963+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=appone2021.herokuapp.com request_id=d1e00110-d2b1-4512-9391-2ab54ac11947 fwd="2.221.116.154" dyno= connect= service= status=503 bytes= protocol=https
2021-01-17T14:42:04.309046+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=appone2021.herokuapp.com request_id=b6446286-f99c-4490-9ed4-ed8071f2d5c1 fwd="2.221.116.154" dyno= connect= service= status=503 bytes= protocol=https
2021-01-17T14:42:04.481028+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=appone2021.herokuapp.com request_id=c6bff236-696b-491d-9831-930f1d114fd8 fwd="2.221.116.154" dyno= connect= service= status=503 bytes= protocol=https
2021-01-17T14:45:18.000000+00:00 app[api]: Build started by user fullstackryan#gmail.com
2021-01-17T14:46:57.165052+00:00 app[api]: Release v25 created by user fullstackryan#gmail.com
2021-01-17T14:46:57.165052+00:00 app[api]: Deploy 5ab4cf89 by user fullstackryan#gmail.com
2021-01-17T14:46:58.334991+00:00 heroku[web.1]: State changed from crashed to starting
2021-01-17T14:47:02.441681+00:00 heroku[web.1]: Starting process with command `target/universal/stage/bin/appone -Dhttp.port=${PORT}`
2021-01-17T14:47:04.351208+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2021-01-17T14:47:04.458310+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
You seem to have most of the pieces, but I don't think you're putting them together correctly.
Heroku Postgres sets the DATABASE_URL environment variable for you:
As part of the provisioning process, a DATABASE_URL config var is added to your app’s configuration. This contains the URL your app uses to access the database.
You appear to already be using this environment variable in your application.conf:
db-config {
driver = "org.postgresql.Driver"
url = ${?DATABASE_URL}
username = ${?DATABASE_USERNAME}
password = ${?DATABASE_PASSWORD}
connection-threads = 4
pool-size = 10
}
The problem is that you are also depending on environment variables called DATABASE_USERNAME and DATABASE_PASSWORD, which Heroku does not provide. That's what is causing your application to fail:
pureconfig.error.ConfigReaderException: Cannot convert configuration to a scala.runtime.Nothing$. Failures are:
at 'appone.db-config':
- (application.conf # jar:file:/app/target/universal/stage/lib/com.fullstackryan.appone-0.0.1-SNAPSHOT.jar!/application.conf: 10) Key not found: 'username'.
- (application.conf # jar:file:/app/target/universal/stage/lib/com.fullstackryan.appone-0.0.1-SNAPSHOT.jar!/application.conf: 10) Key not found: 'password'.
You could try setting them with heroku config:set, but that's not a good idea because
The value of your app’s DATABASE_URL config var might change at any time. You should not rely on this value either inside or outside your Heroku app.
I suggest only setting the url in your application.conf. Then, in your application code, you can parse the URL and connect to your database as you are already trying to do. Since it is a URL, your current approach of instantiating a URI is a good fit.
Side note: Your application code is currently getting DATABASE_URL directly from the environment again. I suspect it would be more idiomatic to retrieve it from whatever configuration object you get from your application.conf, where you have set db-config.url. But I'm not experienced enough in Scala to show the correct approach.
The line below
config <- Stream.eval(LoadConfig[F, Config].load)
was reading my application.conf file which in dev mode is fine as I source the variables mentioned within the application.conf by running source meta/dev.env. meta/dev.env being the location where I store the environment variables mentioned in the application.conf.
However in production (specifically Heroku environment) I could not source meta/prd.env because I could not store variables statically in that location/file as Heroku updates its variables every so often, meaning those variables would become out of date.
With the above in mind, I had to code in such as way that every time the application is run, my apps gets the DATABASE_URL variable injected by Heroku. I created a function for this:
def prodConfig(): Config = {
val dbUri = new URI(System.getenv("DATABASE_URL"))
val username = dbUri.getUserInfo.split(":")(0)
val password = dbUri.getUserInfo.split(":")(1)
val dbUrl = "jdbc:postgresql://" + dbUri.getHost + dbUri.getPath
Config(ServerConfig(5432, dbUri.getHost), DbConfig(dbUrl, username, password, 10))
}
The above code gets DATABASE_URL by using System.getenv("DATABASE_URL"). Then the function splits it into various parts such as username, password etc which I can then pass database config etc.
When in dev I uncomment the first line below and comment out the second line below.
// config <- Stream.eval(LoadConfig[F, Config].load)
conifg = prodConfig()
In dev it reads from application.conf and in prod it will do the System.getenv("DATABASE_URL") which rely on heroku to make sure its provided.
It's not the nicest solution as it relies on commenting and uncommenting when in dev mode but for now it's the best I've got. Would love to hear recommendations on how to make this better.
Hope this helps others who are stuck.
I recommend using JDBC_DATABASE_URL instead. It will be automatically set for your app: https://devcenter.heroku.com/articles/connecting-to-relational-databases-on-heroku-with-java#using-the-database_url-in-plain-jdbc
I tried to use Parse.push.send with cloud function I define to send out a push notification to a device. I follow the guide on CodePath Guide and I receive a success call back in my iOS App. However, none of the remote notification was delivered. I also have the _p_installationKey in my _User collection, and I can verify that the _Installation collection also have an entry matching the address stored in the _User collection. For each cloud function I call, one _PushStatus entry will be inserted, but numSent is 0. Below are the collections stored in my MLab and my environment.
_PushStatus
{
"_id": "3mxSHXoZa0",
"pushTime": "2017-05-19T17:38:46.346Z",
"query": "{\"deviceType\":\"ios\"}",
"payload": "{\"alert\":\"Message: Testing\"}",
"source": "rest",
"status": "running",
"numSent": 0,
"pushHash": "424b520d52c5e20b4eb95be535cb2d54",
"_wperm": [],
"_rperm": [],
"_acl": {},
"_created_at": {
"$date": "2017-05-19T17:38:46.346Z"
},
"_updated_at": {
"$date": "2017-05-19T17:38:46.408Z"
},
"count": 1
}
_Installation
{
"_id": "EMZ8EUmrC6",
"timeZone": "America/Los_Angeles",
"deviceToken": "55097f4ceca541cc5b02b5852d96d10c8238f147c3ec53c3e8a44bfc66520e41",
"deviceType": "ios",
"appVersion": "1",
"appName": "myAppName",
"channels": [
"global"
],
"installationId": "ae540abe-21d4-446f-b90f-f5b6bec04109",
"appIdentifier": "myAppIdentifier",
"parseVersion": "1.14.2",
"localeIdentifier": "en-US",
"badge": 0,
"_created_at": {
"$date": "2017-05-19T06:03:14.614Z"
},
"_updated_at": {
"$date": "2017-05-19T06:03:14.614Z"
}
}
_User
{
"_id": "ZEMtqdJMaw",
"_p_installationKey": "_Installation$EMZ8EUmrC6",
"username": "121259958664",
"_hashed_password": "$2a$10$HR6TtUFB5G3tkeA9LlHbvuKOE2rpG.gvyHqAjsOQBps.X9jQvu9DO",
"_wperm": [
"ZEMtqdJMaw"
],
"_rperm": [
"*",
"ZEMtqdJMaw"
],
"_acl": {
"ZEMtqdJMaw": {
"w": true,
"r": true
},
"*": {
"r": true
}
},
"_created_at": {
"$date": "2017-05-19T06:03:27.637Z"
},
"_updated_at": {
"$date": "2017-05-19T06:03:27.637Z"
}
}
Config Vars in Heroku
main.js
// iOS push testing
Parse.Cloud.define("iosPushTest", function(request, response) {
// request has 2 parameters: params passed by the client and the authorized user
var params = request.params;
var user = request.user;
// Our "Message" class has a "text" key with the body of the message itself
var messageText = params.text;
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo('deviceType', 'ios'); // targeting iOS devices only
Parse.Push.send({
where: pushQuery, // Set our Installation query
data: {
alert: "Message: " + messageText
}
}, { success: function() {
console.log("#### PUSH OK");
response.success('success');
}, error: function(error) {
console.log("#### PUSH ERROR" + error.message);
response.error('failed');
}, useMasterKey: true});
});
index.js
var devCertPath = path.resolve(__dirname, 'ParsePushDevelopmentCertificate.p12');
var pushConfig = {'ios': [
{
pfx: devCertPath, // P12 file only
bundleId: 'myBundleId', // change to match bundleId
production: false // dev certificate
}
]
};
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'myAppId',
masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
liveQuery: {
classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
},
push: pushConfig
});
Logs
at Object.onceWrapper (events.js:293:19)
2017-05-19T18:06:04.498577+00:00 app[web.1]: at emitNone (events.js:91:20)
2017-05-19T18:06:04.498577+00:00 app[web.1]: at TLSSocket.emit (events.js:188:7)
2017-05-19T18:06:04.498578+00:00 app[web.1]: at endReadableNT (_stream_readable.js:975:12)
2017-05-19T18:06:04.498579+00:00 app[web.1]: at process._tickDomainCallback (internal/process/next_tick.js:128:9)
2017-05-19T18:06:04.498579+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:80:11)
2017-05-19T18:06:04.501023+00:00 app[web.1]: verb parse-server-push-adapter APNS APNS Connection 0 Socket Error
2017-05-19T18:06:04.501397+00:00 app[web.1]: Fri, 19 May 2017 18:06:04 GMT apn Socket closed undefined
2017-05-19T18:06:04.501480+00:00 app[web.1]: Fri, 19 May 2017 18:06:04 GMT apn Removing socket from pool undefined
2017-05-19T18:06:04.501686+00:00 app[web.1]: verb parse-server-push-adapter APNS APNS Connection 0 Disconnected
2017-05-19T18:06:04.501787+00:00 app[web.1]: Fri, 19 May 2017 18:06:04 GMT apn 1 left to send
2017-05-19T18:06:20.502222+00:00 app[web.1]: Fri, 19 May 2017 18:06:20 GMT apn Initialising connection
2017-05-19T18:06:20.502541+00:00 app[web.1]: Fri, 19 May 2017 18:06:20 GMT apn 1 left to send
2017-05-19T18:06:20.611635+00:00 app[web.1]: Fri, 19 May 2017 18:06:20 GMT apn Socket error occurred undefined { Error: socket hang up
2017-05-19T18:06:20.611637+00:00 app[web.1]: at TLSSocket.onHangUp (_tls_wrap.js:1120:19)
2017-05-19T18:06:20.611638+00:00 app[web.1]: at Object.onceWrapper (events.js:293:19)
2017-05-19T18:06:20.611639+00:00 app[web.1]: at emitNone (events.js:91:20)
2017-05-19T18:06:20.611652+00:00 app[web.1]: at TLSSocket.emit (events.js:188:7)
2017-05-19T18:06:20.611653+00:00 app[web.1]: at endReadableNT (_stream_readable.js:975:12)
2017-05-19T18:06:20.611654+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:80:11)
2017-05-19T18:06:20.611655+00:00 app[web.1]: at process._tickDomainCallback (internal/process/next_tick.js:128:9) code: 'ECONNRESET' }
2017-05-19T18:06:20.611802+00:00 app[web.1]: Fri, 19 May 2017 18:06:20 GMT apn Destroying connection undefined
2017-05-19T18:06:20.611886+00:00 app[web.1]: Fri, 19 May 2017 18:06:20 GMT apn Removing socket from pool undefined
2017-05-19T18:06:20.612721+00:00 app[web.1]: Fri, 19 May 2017 18:06:20 GMT apn Raising error: { Error: socket hang up
2017-05-19T18:06:20.612723+00:00 app[web.1]: at TLSSocket.onHangUp (_tls_wrap.js:1120:19)
2017-05-19T18:06:20.612724+00:00 app[web.1]: at Object.onceWrapper (events.js:293:19)
2017-05-19T18:06:20.612724+00:00 app[web.1]: at emitNone (events.js:91:20)
2017-05-19T18:06:20.612725+00:00 app[web.1]: at TLSSocket.emit (events.js:188:7)
2017-05-19T18:06:20.612725+00:00 app[web.1]: at endReadableNT (_stream_readable.js:975:12)
2017-05-19T18:06:20.612726+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:80:11)
2017-05-19T18:06:20.612727+00:00 app[web.1]: at process._tickDomainCallback (internal/process/next_tick.js:128:9) code: 'ECONNRESET' } undefined undefined
2017-05-19T18:06:20.612870+00:00 app[web.1]: Fri, 19 May 2017 18:06:20 GMT apn Error occurred with trace: Error: socket hang up
2017-05-19T18:06:20.612871+00:00 app[web.1]: at TLSSocket.onHangUp (_tls_wrap.js:1120:19)
2017-05-19T18:06:20.612872+00:00 app[web.1]: at Object.onceWrapper (events.js:293:19)
2017-05-19T18:06:20.612872+00:00 app[web.1]: at emitNone (events.js:91:20)
2017-05-19T18:06:20.612873+00:00 app[web.1]: at TLSSocket.emit (events.js:188:7)
2017-05-19T18:06:20.612873+00:00 app[web.1]: at endReadableNT (_stream_readable.js:975:12)
2017-05-19T18:06:20.612874+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:80:11)
2017-05-19T18:06:20.612875+00:00 app[web.1]: at process._tickDomainCallback (internal/process/next_tick.js:128:9)
2017-05-19T18:06:20.613192+00:00 app[web.1]: verb parse-server-push-adapter APNS APNS Connection 0 Socket Error
2017-05-19T18:06:20.613647+00:00 app[web.1]: Fri, 19 May 2017 18:06:20 GMT apn Socket closed undefined
2017-05-19T18:06:20.613741+00:00 app[web.1]: Fri, 19 May 2017 18:06:20 GMT apn Removing socket from pool undefined
2017-05-19T18:06:20.624646+00:00 app[web.1]: verb parse-server-push-adapter APNS APNS Connection 0 Disconnected
2017-05-19T18:06:20.624800+00:00 app[web.1]: Fri, 19 May 2017 18:06:20 GMT apn 1 left to send
2017-05-19T18:06:52.614568+00:00 app[web.1]: Fri, 19 May 2017 18:06:52 GMT apn Initialising connection
2017-05-19T18:06:52.614810+00:00 app[web.1]: Fri, 19 May 2017 18:06:52 GMT apn 1 left to send
2017-05-19T18:06:52.758861+00:00 app[web.1]: Fri, 19 May 2017 18:06:52 GMT apn Socket error occurred undefined { Error: socket hang up
2017-05-19T18:06:52.758864+00:00 app[web.1]: at TLSSocket.onHangUp (_tls_wrap.js:1120:19)
2017-05-19T18:06:52.758865+00:00 app[web.1]: at Object.onceWrapper (events.js:293:19)
2017-05-19T18:06:52.758866+00:00 app[web.1]: at emitNone (events.js:91:20)
2017-05-19T18:06:52.758866+00:00 app[web.1]: at TLSSocket.emit (events.js:188:7)
2017-05-19T18:06:52.758867+00:00 app[web.1]: at endReadableNT (_stream_readable.js:975:12)
2017-05-19T18:06:52.758868+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:80:11)
2017-05-19T18:06:52.758869+00:00 app[web.1]: at process._tickDomainCallback (internal/process/next_tick.js:128:9) code: 'ECONNRESET' }
2017-05-19T18:06:52.759154+00:00 app[web.1]: Fri, 19 May 2017 18:06:52 GMT apn Destroying connection undefined
2017-05-19T18:06:52.759277+00:00 app[web.1]: Fri, 19 May 2017 18:06:52 GMT apn Removing socket from pool undefined
2017-05-19T18:06:52.759717+00:00 app[web.1]: Fri, 19 May 2017 18:06:52 GMT apn Raising error: { Error: socket hang up
2017-05-19T18:06:52.759719+00:00 app[web.1]: at TLSSocket.onHangUp (_tls_wrap.js:1120:19)
2017-05-19T18:06:52.759720+00:00 app[web.1]: at Object.onceWrapper (events.js:293:19)
2017-05-19T18:06:52.759720+00:00 app[web.1]: at emitNone (events.js:91:20)
2017-05-19T18:06:52.759721+00:00 app[web.1]: at TLSSocket.emit (events.js:188:7)
2017-05-19T18:06:52.759722+00:00 app[web.1]: at endReadableNT (_stream_readable.js:975:12)
2017-05-19T18:06:52.759722+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:80:11)
2017-05-19T18:06:52.759723+00:00 app[web.1]: at process._tickDomainCallback (internal/process/next_tick.js:128:9) code: 'ECONNRESET' } undefined undefined
2017-05-19T18:06:52.759875+00:00 app[web.1]: Fri, 19 May 2017 18:06:52 GMT apn Error occurred with trace: Error: socket hang up
2017-05-19T18:06:52.759876+00:00 app[web.1]: at TLSSocket.onHangUp (_tls_wrap.js:1120:19)
2017-05-19T18:06:52.759877+00:00 app[web.1]: at Object.onceWrapper (events.js:293:19)
2017-05-19T18:06:52.759878+00:00 app[web.1]: at emitNone (events.js:91:20)
2017-05-19T18:06:52.759878+00:00 app[web.1]: at TLSSocket.emit (events.js:188:7)
2017-05-19T18:06:52.759879+00:00 app[web.1]: at endReadableNT (_stream_readable.js:975:12)
2017-05-19T18:06:52.759880+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:80:11)
2017-05-19T18:06:52.759880+00:00 app[web.1]: at process._tickDomainCallback (internal/process/next_tick.js:128:9)
2017-05-19T18:06:52.760240+00:00 app[web.1]: verb parse-server-push-adapter APNS APNS Connection 0 Socket Error
2017-05-19T18:06:52.760741+00:00 app[web.1]: Fri, 19 May 2017 18:06:52 GMT apn Socket closed undefined
2017-05-19T18:06:52.760851+00:00 app[web.1]: Fri, 19 May 2017 18:06:52 GMT apn Removing socket from pool undefined
2017-05-19T18:06:52.761152+00:00 app[web.1]: verb parse-server-push-adapter APNS APNS Connection 0 Disconnected
2017-05-19T18:06:52.761244+00:00 app[web.1]: Fri, 19 May 2017 18:06:52 GMT apn 1 left to send
Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...
2017-05-19T18:06:52.759877+00:00 app[web.1]: at Object.onceWrapper (events.js:293:19)
2017-05-19T18:06:52.759878+00:00 app[web.1]: at emitNone (events.js:91:20)
2017-05-19T18:06:52.759878+00:00 app[web.1]: at TLSSocket.emit (events.js:188:7)
2017-05-19T18:06:52.759879+00:00 app[web.1]: at endReadableNT (_stream_readable.js:975:12)
2017-05-19T18:06:52.759880+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:80:11)
2017-05-19T18:06:52.759880+00:00 app[web.1]: at process._tickDomainCallback (internal/process/next_tick.js:128:9)
2017-05-19T18:06:52.760240+00:00 app[web.1]: verb parse-server-push-adapter APNS APNS Connection 0 Socket Error
2017-05-19T18:06:52.760741+00:00 app[web.1]: Fri, 19 May 2017 18:06:52 GMT apn Socket closed undefined
2017-05-19T18:06:52.760851+00:00 app[web.1]: Fri, 19 May 2017 18:06:52 GMT apn Removing socket from pool undefined
2017-05-19T18:06:52.761152+00:00 app[web.1]: verb parse-server-push-adapter APNS APNS Connection 0 Disconnected
2017-05-19T18:06:52.761244+00:00 app[web.1]: Fri, 19 May 2017 18:06:52 GMT apn 1 left to send
2017-05-19T18:07:42.422486+00:00 heroku[router]: at=info method=POST path="/parse/push" host=spottune.herokuapp.com request_id=4ebb4912-b4d5-42bd-8057-21cb23763300 fwd="54.204.64.16" dyno=web.1 connect=0ms service=18ms status=200 bytes=533 protocol=https
2017-05-19T18:07:42.368169+00:00 app[web.1]: [36mverbose[39m: REQUEST for [POST] /parse/functions/iosPushTest: {
2017-05-19T18:07:42.368182+00:00 app[web.1]: "text": "Testing"
2017-05-19T18:07:42.368186+00:00 app[web.1]: } method=POST, url=/parse/functions/iosPushTest, host=myapp.herokuapp.com, connection=close, x-parse-app-display-version=1.0, x-parse-application-id=applicationID, accept=*/*, accept-language=en-us, x-parse-os-version=10.3.2 (14F5080a), user-agent=Spottunes/1 CFNetwork/811.5.3 Darwin/16.6.0, x-parse-app-build-version=1, content-type=application/json; charset=utf-8, x-parse-session-token=r:d574da7c3405de7c7cad42c147bcec85, x-parse-client-version=i1.14.2, x-parse-installation-id=ae540abe-21d4-446f-b90f-f5b6bec04109, accept-encoding=gzip, deflate, x-request-id=1d2c625e-2d55-4270-b9b0-9b3c74ea457d, x-forwarded-for=128.54.116.32, x-forwarded-proto=https, x-forwarded-port=443, via=1.1 vegur, connect-time=0, x-request-start=1495217262279, total-route-time=0, content-length=18, text=Testing
2017-05-19T18:07:42.409208+00:00 app[web.1]: [36mverbose[39m: REQUEST for [POST] /parse/push: {
2017-05-19T18:07:42.409211+00:00 app[web.1]: "where": {
2017-05-19T18:07:42.409212+00:00 app[web.1]: "deviceType": "ios"
2017-05-19T18:07:42.409213+00:00 app[web.1]: },
2017-05-19T18:07:42.409214+00:00 app[web.1]: "data": {
2017-05-19T18:07:42.409214+00:00 app[web.1]: "alert": "Message: Testing"
2017-05-19T18:07:42.409215+00:00 app[web.1]: }
2017-05-19T18:07:42.409218+00:00 app[web.1]: } method=POST, url=/parse/push, host=myapp.herokuapp.com, connection=close, user-agent=node-XMLHttpRequest, Parse/js1.9.2 (NodeJS 7.10.0), accept=*/*, content-type=text/plain, x-request-id=4ebb4912-b4d5-42bd-8057-21cb23763300, x-forwarded-for=54.204.64.16, x-forwarded-proto=https, x-forwarded-port=443, via=1.1 vegur, connect-time=0, x-request-start=1495217262403, total-route-time=0, content-length=237, deviceType=ios, alert=Message: Testing
2017-05-19T18:07:42.410004+00:00 app[web.1]: [33mwarn[39m: Trying to schedule a push while server is not configured.
2017-05-19T18:07:42.410267+00:00 app[web.1]: [33mwarn[39m: Push will be sent immediately
2017-05-19T18:07:42.420038+00:00 app[web.1]: [36mverbose[39m: RESPONSE from [POST] /parse/push: {
2017-05-19T18:07:42.420040+00:00 app[web.1]: "headers": {
2017-05-19T18:07:42.420041+00:00 app[web.1]: "X-Parse-Push-Status-Id": "OBtnkjGpL8"
2017-05-19T18:07:42.420042+00:00 app[web.1]: },
2017-05-19T18:07:42.420043+00:00 app[web.1]: "response": {
2017-05-19T18:07:42.420043+00:00 app[web.1]: "result": true
2017-05-19T18:07:42.420044+00:00 app[web.1]: }
2017-05-19T18:07:42.420044+00:00 app[web.1]: } X-Parse-Push-Status-Id=OBtnkjGpL8, result=true
2017-05-19T18:07:42.428718+00:00 app[web.1]: #### PUSH OK
2017-05-19T18:07:42.429322+00:00 app[web.1]: [32minfo[39m: Ran cloud function iosPushTest for user ZEMtqdJMaw with:
2017-05-19T18:07:42.429324+00:00 app[web.1]: Input: {"text":"Testing"}
2017-05-19T18:07:42.429325+00:00 app[web.1]: Result: "success" functionName=iosPushTest, text=Testing, user=ZEMtqdJMaw
2017-05-19T18:07:42.430053+00:00 app[web.1]: [36mverbose[39m: RESPONSE from [POST] /parse/functions/iosPushTest: {
2017-05-19T18:07:42.430054+00:00 app[web.1]: "response": {
2017-05-19T18:07:42.430055+00:00 app[web.1]: "result": "success"
2017-05-19T18:07:42.430056+00:00 app[web.1]: }
2017-05-19T18:07:42.430056+00:00 app[web.1]: } result=success
2017-05-19T18:07:42.433082+00:00 app[web.1]: [36mverbose[39m: _PushStatus OBtnkjGpL8: sending push to 1 installations
2017-05-19T18:07:42.458687+00:00 app[web.1]: Fri, 19 May 2017 18:07:42 GMT apn 2 left to send
2017-05-19T18:07:42.432839+00:00 heroku[router]: at=info method=POST path="/parse/functions/iosPushTest" host=spottune.herokuapp.com request_id=1d2c625e-2d55-4270-b9b0-9b3c74ea457d fwd="128.54.116.32" dyno=web.1 connect=0ms service=151ms status=200 bytes=502 protocol=https
2017-05-19T18:07:56.765036+00:00 app[web.1]: Fri, 19 May 2017 18:07:56 GMT apn Initialising connection
2017-05-19T18:07:56.767442+00:00 app[web.1]: Fri, 19 May 2017 18:07:56 GMT apn 2 left to send
2017-05-19T18:07:57.045303+00:00 app[web.1]: Fri, 19 May 2017 18:07:57 GMT apn Socket error occurred undefined { Error: socket hang up
2017-05-19T18:07:57.045317+00:00 app[web.1]: at TLSSocket.onHangUp (_tls_wrap.js:1120:19)
2017-05-19T18:07:57.045318+00:00 app[web.1]: at Object.onceWrapper (events.js:293:19)
2017-05-19T18:07:57.045318+00:00 app[web.1]: at emitNone (events.js:91:20)
2017-05-19T18:07:57.045319+00:00 app[web.1]: at TLSSocket.emit (events.js:188:7)
2017-05-19T18:07:57.045319+00:00 app[web.1]: at endReadableNT (_stream_readable.js:975:12)
2017-05-19T18:07:57.045320+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:80:11)
2017-05-19T18:07:57.045320+00:00 app[web.1]: at process._tickDomainCallback (internal/process/next_tick.js:128:9) code: 'ECONNRESET' }
2017-05-19T18:07:57.045416+00:00 app[web.1]: Fri, 19 May 2017 18:07:57 GMT apn Destroying connection undefined
2017-05-19T18:07:57.045473+00:00 app[web.1]: Fri, 19 May 2017 18:07:57 GMT apn Removing socket from pool undefined
2017-05-19T18:07:57.045796+00:00 app[web.1]: Fri, 19 May 2017 18:07:57 GMT apn Raising error: { Error: socket hang up
2017-05-19T18:07:57.045797+00:00 app[web.1]: at TLSSocket.onHangUp (_tls_wrap.js:1120:19)
2017-05-19T18:07:57.045797+00:00 app[web.1]: at Object.onceWrapper (events.js:293:19)
2017-05-19T18:07:57.045798+00:00 app[web.1]: at emitNone (events.js:91:20)
2017-05-19T18:07:57.045798+00:00 app[web.1]: at TLSSocket.emit (events.js:188:7)
2017-05-19T18:07:57.045799+00:00 app[web.1]: at endReadableNT (_stream_readable.js:975:12)
2017-05-19T18:07:57.045799+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:80:11)
2017-05-19T18:07:57.045800+00:00 app[web.1]: at process._tickDomainCallback (internal/process/next_tick.js:128:9) code: 'ECONNRESET' } undefined undefined
2017-05-19T18:07:57.045910+00:00 app[web.1]: Fri, 19 May 2017 18:07:57 GMT apn Error occurred with trace: Error: socket hang up
2017-05-19T18:07:57.045912+00:00 app[web.1]: at TLSSocket.onHangUp (_tls_wrap.js:1120:19)
2017-05-19T18:07:57.045912+00:00 app[web.1]: at Object.onceWrapper (events.js:293:19)
2017-05-19T18:07:57.045913+00:00 app[web.1]: at emitNone (events.js:91:20)
2017-05-19T18:07:57.045914+00:00 app[web.1]: at TLSSocket.emit (events.js:188:7)
2017-05-19T18:07:57.045914+00:00 app[web.1]: at endReadableNT (_stream_readable.js:975:12)
2017-05-19T18:07:57.045915+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:80:11)
2017-05-19T18:07:57.045916+00:00 app[web.1]: at process._tickDomainCallback (internal/process/next_tick.js:128:9)
2017-05-19T18:07:57.046198+00:00 app[web.1]: verb parse-server-push-adapter APNS APNS Connection 0 Socket Error
2017-05-19T18:07:57.046589+00:00 app[web.1]: Fri, 19 May 2017 18:07:57 GMT apn Socket closed undefined
2017-05-19T18:07:57.046677+00:00 app[web.1]: Fri, 19 May 2017 18:07:57 GMT apn Removing socket from pool undefined
2017-05-19T18:07:57.046816+00:00 app[web.1]: verb parse-server-push-adapter APNS APNS Connection 0 Disconnected
2017-05-19T18:07:57.046889+00:00 app[web.1]: Fri, 19 May 2017 18:07:57 GMT apn 2 left to send
Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...
2017-05-19T18:07:57.045912+00:00 app[web.1]: at Object.onceWrapper (events.js:293:19)
2017-05-19T18:07:57.045913+00:00 app[web.1]: at emitNone (events.js:91:20)
2017-05-19T18:07:57.045914+00:00 app[web.1]: at TLSSocket.emit (events.js:188:7)
2017-05-19T18:07:57.045914+00:00 app[web.1]: at endReadableNT (_stream_readable.js:975:12)
2017-05-19T18:07:57.045915+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:80:11)
2017-05-19T18:07:57.045916+00:00 app[web.1]: at process._tickDomainCallback (internal/process/next_tick.js:128:9)
2017-05-19T18:07:57.046198+00:00 app[web.1]: verb parse-server-push-adapter APNS APNS Connection 0 Socket Error
2017-05-19T18:07:57.046589+00:00 app[web.1]: Fri, 19 May 2017 18:07:57 GMT apn Socket closed undefined
2017-05-19T18:07:57.046677+00:00 app[web.1]: Fri, 19 May 2017 18:07:57 GMT apn Removing socket from pool undefined
2017-05-19T18:07:57.046816+00:00 app[web.1]: verb parse-server-push-adapter APNS APNS Connection 0 Disconnected
2017-05-19T18:07:57.046889+00:00 app[web.1]: Fri, 19 May 2017 18:07:57 GMT apn 2 left to send
Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...
Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...
2017-05-19T18:07:57.045912+00:00 app[web.1]: at Object.onceWrapper (events.js:293:19)
2017-05-19T18:07:57.045913+00:00 app[web.1]: at emitNone (events.js:91:20)
2017-05-19T18:07:57.045914+00:00 app[web.1]: at TLSSocket.emit (events.js:188:7)
2017-05-19T18:07:57.045914+00:00 app[web.1]: at endReadableNT (_stream_readable.js:975:12)
2017-05-19T18:07:57.045915+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:80:11)
2017-05-19T18:07:57.045916+00:00 app[web.1]: at process._tickDomainCallback (internal/process/next_tick.js:128:9)
2017-05-19T18:07:57.046198+00:00 app[web.1]: verb parse-server-push-adapter APNS APNS Connection 0 Socket Error
2017-05-19T18:07:57.046589+00:00 app[web.1]: Fri, 19 May 2017 18:07:57 GMT apn Socket closed undefined
2017-05-19T18:07:57.046677+00:00 app[web.1]: Fri, 19 May 2017 18:07:57 GMT apn Removing socket from pool undefined
2017-05-19T18:07:57.046816+00:00 app[web.1]: verb parse-server-push-adapter APNS APNS Connection 0 Disconnected
2017-05-19T18:07:57.046889+00:00 app[web.1]: Fri, 19 May 2017 18:07:57 GMT apn 2 left to send
Call using Swift
print("sending push notification...")
let param: [String: Any] = [
"text" : "Testing"
]
PFCloud.callFunction(inBackground: "iosPushTest", withParameters: param) { (response, error) in
print("push \(response)")
}
Xcode console
sending push notification...
push Optional(success)
Not sure what else should I add in order to make this work. Any help is appreciated
I don't see a file path to your APNS cert in your configs. That needs to be included, and there is a little bit of extra configuration to do in your index.js to enable Push. Not sure how it's hadnled when you call Push.send() without the extra configuration enabled, but that looks to be going through. So, my bet is invalid APNS. If you debug this locally, you'd likely get some more useful server output.
I am trying to deploy my app to Heroku. It works perfectly fine when run locally. From the moment I deployed it (deploying through github integration) I received the generic Application Error screen. Below are my heroku logs. These actually run three times but there was no point in me posting the same thing three times. They always end with:
2017-05-02T14:59:26.033702+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=calm-crag-40902.herokuapp.com request_id=6b64883e-9697-4d58-84d9-2f173d5b4cb1 fwd="70.
54.76.222" dyno= connect= service= status=503 bytes= protocol=https
2017-05-02T14:59:27.425435+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=calm-crag-40902.herokuapp.com request_id=d3719d8f-4670-4621-a044-a511ee6884
10 fwd="70.54.76.222" dyno= connect= service= status=503 bytes= protocol=https
This will print 2 to 4 times after each consecutive error screen. The first error is regarding the .env files not running and the second is trying to connect to sequelize. My primary focus is sorting out the .env because if that is sorted out, at least the app will show my app will be visible.
.env error:
{ Error: ENOENT: no such file or directory, open '.env'
2017-05-02T16:09:39.622865+00:00 app[web.1]: at Error (native)
2017-05-02T16:09:39.622866+00:00 app[web.1]: at Object.fs.openSync (fs.js:641:18)
2017-05-02T16:09:39.622867+00:00 app[web.1]: at Object.fs.readFileSync (fs.js:509:33)
2017-05-02T16:09:39.622867+00:00 app[web.1]: at Object.config (/app/node_modules/dotenv/lib/main.js:30:37)
2017-05-02T16:09:39.622868+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:3:19)
2017-05-02T16:09:39.622869+00:00 app[web.1]: at Module._compile (module.js:570:32)
2017-05-02T16:09:39.622869+00:00 app[web.1]: at Object.Module._extensions..js (module.js:579:10)
2017-05-02T16:09:39.622870+00:00 app[web.1]: at Module.load (module.js:487:32)
2017-05-02T16:09:39.622871+00:00 app[web.1]: at tryModuleLoad (module.js:446:12)
2017-05-02T16:09:39.622871+00:00 app[web.1]: at Function.Module._load (module.js:438:3) errno: -2, code: 'ENOENT', syscall: 'open', path: '.env' }
2017-05-02T16:09:40.242885+00:00 app[web.1]: Unhandled rejection
Sequelize error:
SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:5432
2017-05-02T16:09:40.242902+00:00 app[web.1]: at /app/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:98:20
2017-05-02T16:09:40.242903+00:00 app[web.1]: at Connection.<anonymous> (/app/node_modules/pg/lib/client.js:186:5)
2017-05-02T16:09:40.242904+00:00 app[web.1]: at emitOne (events.js:96:13)
2017-05-02T16:09:40.242905+00:00 app[web.1]: at Connection.emit (events.js:188:7)
2017-05-02T16:09:40.242905+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/pg/lib/connection.js:86:10)
2017-05-02T16:09:40.242906+00:00 app[web.1]: at emitOne (events.js:96:13)
2017-05-02T16:09:40.242907+00:00 app[web.1]: at emitErrorNT (net.js:1281:8)
2017-05-02T16:09:40.242907+00:00 app[web.1]: at Socket.emit (events.js:188:7)
2017-05-02T16:09:40.242909+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:104:9)
2017-05-02T16:09:40.242908+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:80:11)
2017-05-02T16:09:40.360035+00:00 heroku[web.1]: Process exited with status 0
2017-05-02T16:09:40.373996+00:00 heroku[web.1]: State changed from starting to crashed
This is my index.js:
'use strict';
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(module.filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/config.json')[env];
const db = {};
if (config.use_env_variable) {
const sequelize = new Sequelize(process.env[config.use_env_variable]);
} else {
const sequelize = new Sequelize(config.database, config.username, config.password, config);
}
fs
.readdirSync(__dirname)
.filter((file) => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach((file) => {
const model = sequelize['import'](path.join(__dirname, file));
db[model.name] = model;
});
Object.keys(db).forEach((modelName) => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});
db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db;
config.json:
{
"development": {
"username": "",
"password": "",
"database": "late_file",
"host": "127.0.0.1",
"dialect": "postgres"
},
"test": {
"username": "",
"password": "",
"database": "database_test",
"host": "127.0.0.1",
"dialect": "postgres"
},
"production": {
"use_env_variable": "DATABASE_URL",
"dialect": "postgres"
}
}
.env, modified to exclude specific names of things
DB_HOST=localhost
DB_USER=
DB_PASS=
DB_NAME=
DB_SSL=true if heroku
DB_PORT=5432
DATABASE_URL=postgres://appropriate/url
applicable part of server.js
const pg = require('pg');
pg.defaults.ssl = true;
pg.connect(process.env.DATABASE_URL, function(err, client) {
if (err) throw err;
console.log('Connected to postgres! Getting schemas...');
client
.query('SELECT table_schema,table_name FROM information_schema.tables;')
.on('row', function(row) {
console.log(JSON.stringify(row));
});
});
Any help would be greatly appreciated!
Thanks in advance for anyone who offers any support!
Brandon,
I am running an app on Heroku using JAWS_DB and MySQL, but otherwise identical config.json and index.js. In my case on Heroku, the "if (config.use_env_variable) {const sequelize = new Sequelize(process.env[config.use_env_variable])" statement connects to the database without error. The logs appear to point to the "pg.connect" failing in server.js. It's not clear to me (without seeing the rest of your code) why you need to connect to the database in index.js, and then connect again in server.js. If you can remove the connection from pg.connect and try to run with just the connection from index.js it may stop this error.