Code Monkey home page Code Monkey logo

Comments (6)

jmcgnh avatar jmcgnh commented on July 29, 2024

I didn't find a way to do this without modifying .bin/serve:

3cc3895

You should be able to ignore the parts about Docker. My goal was to be able to switch between http or https with just env changes, once I merged in my changes to .bin/serve

from phant.

chenmingzhang avatar chenmingzhang commented on July 29, 2024

thanks Jim!
this might be a silly question, where to define process.env?

currently i run the server and it says

$phant
process.env.PHANT_SERVER_STLE = undefined
phant http server running on port 8080
phant telnet server running on port 8081

which means it is still running under http type.

from phant.

chenmingzhang avatar chenmingzhang commented on July 29, 2024

just wish to give you an update:

I have added
process.env.PHANT_SERVERSTYLE='http'
to serve file

the output is:
$ phantj
process.env.PHANT_SERVER_STLE = http
phant http server running on port 8080
phant telnet server running on port 8081

while i add
process.env.PHANT_SERVERSTYLE='https'
to serve file

the output is:
$phantj
process.env.PHANT_SERVER_STLE = https
fs.js:641
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^

TypeError: path must be a string or Buffer
at TypeError (native)
at Object.fs.openSync (fs.js:641:18)
at Object.fs.readFileSync (fs.js:509:33)
at Object.app.credentials (/usr/lib/node_modules/phantj/lib/https_server.js:80:14)
at Object.app.listen (/usr/lib/node_modules/phantj/lib/https_server.js:42:41)
at Object. (/usr/lib/node_modules/phantj/.bin/serve:56:11)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)

from phant.

jmcgnh avatar jmcgnh commented on July 29, 2024

I thought I had gotten that version working, but it's apparently not what I'm currently running.

process.env is supposed to be created by the dotenv.load call close to the beginning of .bin/serve. I know I was having difficulty figuring out which directories were being looked at for the .env file.

So let me give you the some diffs for the more brute-force version:

45c46
< Phant.HttpServer.listen(http_port);
---
> Phant.HttpsServer.listen(http_port);
56,57c57,58
< // attach manager to http server
< Phant.HttpServer.use(httpManager);
---
> // attach manager to https server
> Phant.HttpsServer.use(httpManager);
59,60c60,61
< // attach input to http server
< Phant.HttpServer.use(httpInput);
---
> // attach input to https server
> Phant.HttpsServer.use(httpInput);
62,63c63,64
< // attach output to http server
< Phant.HttpServer.use(httpOutput);
---
> // attach output to https server
> Phant.HttpsServer.use(httpOutput);
81c82
< console.log('phant http server running on port ' + http_port);
---
> console.log('phant https server running on port ' + http_port);

You also need to supply pointers to your cert. Other people have done this by modifying HttpsServer.js but I think I had it working by adding lines like the following to .bin/serve after HttpsServer is 'require'd but before it is instantiated.

+    Phant.HttpsServer.cert = process.env.PHANT_CERTFILE;
+    Phant.HttpsServer.key = process.env.PHANT_KEYFILE;

where you can directly assign strings for the paths to these files on your server instance, unless you figure out how to do the dotenv processing to work better than I was able to do.

=====

As you can see, I was trying to make changes that would allow a version of Phant that would be entirely configured from env files and could be packaged as a Docker container. Changes to .bin/env seemed unavoidable, but it seemed I could leave everything else untouched.

As with all too many projects, this moved further and further down the stack to the point where it was no longer making any progress. I like the approach Phant takes better than other loggers I have looked at because it has a fairly simple web-based API that can be implemented naively, without requiring extensive driver code in each implementation language. In some ways, it's fine that Sparkfun does not seem to have been making any changes or improvements to it. I still hope to get back to working on this task so that my occupation of the namespace with "phantj" is not for nought.

from phant.

don avatar don commented on July 29, 2024

Rather than change Phant, I set up a virtual host in nginx and proxy http and https traffic to 8080

server {
  listen 80;
  listen [::]:80;
  server_name phant.example.com;

  # SSL configuration
  listen 443;
  listen [::]:443;
  include snippets/ssl-params.conf;
  ssl_certificate /etc/letsencrypt/live/server/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/server/privkey.pem;

  root /var/www/phant/html;

  # skip the proxy for letsencrypt
  location /.well-known {
  }

  location / {
    proxy_pass http://localhost:8080/;
  }
}

from phant.

bboyho avatar bboyho commented on July 29, 2024

Phant is No Longer in Operation

Unfortunately Phant, our data-streaming service, is no longer in service and will be discontinued. The system has reached capacity and, like a less-adventurous Cassini, has plunged conclusively into a fiery and permanent retirement. There are several other maker-friendly, data-streaming services and/or IoT platforms available as alternatives. The three we recommend are Blynk, ThingSpeak, and Cayenne. You can read our blog post [ https://www.sparkfun.com/news/2413 ] on the topic for an overview and helpful links for each platform.

from phant.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.