Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

localhost:7676 connection refused using tutorial template #4

Open
JaviSoto opened this issue Jan 29, 2023 · 7 comments
Open

localhost:7676 connection refused using tutorial template #4

JaviSoto opened this issue Jan 29, 2023 · 7 comments

Comments

@JaviSoto
Copy link

JaviSoto commented Jan 29, 2023

Hi! Congrats for shipping :) really excited about this.

I followed the tutorial in https://swift.cloud/blog/deploy-server-side-swift-applications-on-vercel, and I can't figure out what I may be doing wrong. I created a project that is essentially the same as https://github.com/swift-cloud/vercel-starter-kit. When I run swift package --disable-sandbox vercel dev I see the following output, seemingly showing everything's OK:

-------------------------------------------------------------------------
Starting dev server: http://localhost:7676
-------------------------------------------------------------------------


/Applications/Xcode-14.2.0-Release.Candidate.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift run --package-path /Users/javi/Documents/Projects/Personal/Website

  [0/1] Planning build
  Building for debugging...
  Build complete! (1.08s)
  2023-01-29T11:58:12-0800 info LocalLambdaServer : [AWSLambdaRuntimeCore] LocalLambdaServer started and listening on 127.0.0.1:7000, receiving events on /invoke
  2023-01-29T11:58:12-0800 info Lambda : [AWSLambdaRuntimeCore] lambda runtime starting with LambdaConfiguration
  General(logLevel: info))
  Lifecycle(id: 190925014293333, maxTimes: 0, stopSignal: TERM)
  RuntimeEngine(ip: 127.0.0.1, port: 7000, requestTimeout: nil

However, opening http://localhost:7676 on a browser doesn't load (ERR_CONNECTION_REFUSED in Chrome).

Looking at the sources I can't figure out what it may be. I thought maybe it was because I didn't have node installed (although I'm surprised I didn't see an error about it?). But after installing it, i see the same output when invoking the plugin and the same result.

Is there anything else I can to do debug this? Thanks!

@AndrewBarba
Copy link
Contributor

AndrewBarba commented Jan 29, 2023

@JaviSoto I'm taking a look now - it certainly seems related to not having Node installed. I'm wondering if im swallowing that error somewhere. Can you try running node --version and posting the output here?

Can you also post output of manually running the node server from the root directory of your project:

node .build/checkouts/Vercel/Plugins/VercelPackager/Server/server.js

@JaviSoto
Copy link
Author

$ node --version
v19.5.0

If I run that node command directly, I can load the server on my browser! So at least we've narrowed it down to the plugin talking to node?

@JaviSoto
Copy link
Author

If I run swift package --disable-sandbox vercel dev, I can't see any node process with ps, which seems to confirm that too

@AndrewBarba
Copy link
Contributor

AndrewBarba commented Jan 29, 2023

I just pushed up a debug branch, can you switch to this and post output again:

.package(url: "https://github.com/swift-cloud/Vercel", branch: "ab/debug-node-server")

@JaviSoto
Copy link
Author

Indeed:

Plugin does not have access to a tool named ‘node’

I installed node using homebrew:

$ which node

/opt/homebrew/bin/node

@AndrewBarba
Copy link
Contributor

AndrewBarba commented Jan 30, 2023

So strange, this is my output as well:

➜  Vercel git:(ab/debug-node-server) which node

/opt/homebrew/bin/node

I'm going to do some research today to see if this is a permissions issue with homebrew. In the meantime you can probably uninstall node via homebrew and install Node v18 (I haven't tested on v19 although im sure it works) directly from here: https://nodejs.org/en/

@JaviSoto
Copy link
Author

I'm looking at the code in https://github.com/swift-cloud/Vercel/blob/main/Plugins/VercelPackager/Shell.swift, and some old code of mine, and I think I remember what the problem is now: when you invoke a program like that, the user terminal environment isn't loaded normally, so PATH isn't going to have the right values to be able to find node. A work-around I have used is to set Process.launchPath to "/bin/bash", then set Process.arguments to ["-l", "-c", "node"]. That will cause the user's bashrc etc to be loaded. Except it would have to handle zsh being the default console as well I suppose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants