Skip to content
This repository has been archived by the owner on Aug 24, 2023. It is now read-only.

Use Heroku to Deploy #12

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions HerokuDockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH
RUN apt-get update \
&& apt-get install -y tzdata \
&& apt-get -y upgrade && apt-get install -y build-essential curl wget git vim libboost-all-dev
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash \
&& apt-get install -y nodejs \
&& npm install -y -g ssvmup --unsafe-perm \
&& npm install -y ssvm \
&& npm install express express-fileupload
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ADD . ./
RUN ssvmup build
CMD node node/app.js
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ $ curl http://localhost:3000/?name=SSVM
hello SSVM
```

## Use Heroku to Deploy
Use this button [![Heroku Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/nizam0906/ssvm-nodejs-starter)

![SSVM](https://github.com/nizam0906/ssvm-nodejs-starter/blob/master/docs/img/heroku.gif?raw=true)

Or create a Heroku app manually:

```
$ heroku create
$ heroku stack:set container
$ git push heroku master
...
remote: Verifying deploy... done.
To https://git.heroku.com/ssvm-nodejs-starter.git
* [new branch] master -> master
```

## Use VSCode Codespace

Expand Down
10 changes: 10 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "ssvm-nodejs-starter",
"description": "A template project to run Rust functions in Node.js through the Second State WebAssembly engine.",
"stack": "container",
"env":{
"HEROKU_APP_NAME": {
"required": true
}
}
}
Binary file added docs/img/heroku.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions heroku.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build:
docker:
web: HerokuDockerfile
7 changes: 4 additions & 3 deletions node/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ const { say } = require('../pkg/ssvm_nodejs_starter_lib.js');

const http = require('http');
const url = require('url');
const hostname = '0.0.0.0';
const port = 3000;
const hostname = '0.0.0.0';
const port = process.env.PORT || 3000;
const appname = (process.env.HEROKU_APP_NAME) ? process.env.HEROKU_APP_NAME + '.herokuapp.com' : hostname + ':' + port;

const server = http.createServer((req, res) => {
const queryObject = url.parse(req.url,true).query;
if (!queryObject['name']) {
res.end(`Please use command curl http://${hostname}:${port}/?name=MyName \n`);
res.end(`Please use command curl http://${appname}/?name=MyName \n`);
} else {
res.end(say(queryObject['name']) + '\n');
}
Expand Down