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

Reverse Pull Request for final submission #7

Open
wants to merge 12 commits into
base: submission
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
107 changes: 68 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,87 @@

# Simple-app-template ~ Node-hub

## 1. Ready (Setup)
## **1. Ready (Setup)**

[Download Node/NPM](https://nodejs.org/en/download/) if not already installed

In a new folder, run: <br>
`git clone https://github.com/node-hub/AppTemplate`<br>
`git clone https://github.com/node-hub/dumb-client`

In two terminal tabs and in this order
1. In the AppTemplate folder =>
* `npm install`
* `node index.js`
```
git clone https://github.com/node-hub/simple-app-template
```

2. In the Simple-app-template folder =>
In two terminal tabs and in this order<br>
<span>1. In the AppTemplate folder =>
* `npm install`
- Installs all dependencies for the app to work
* `node index.js`
- Should pull up our client
- type command `/launch http://localhost:4444` ~ Changes socket to direct connect to your server (could be a different port if you changed the default)
<br>
You should be able to see on the client a bunch of messages every second if everything is connected!

## 2. Set (App logic)
#### IMPORTANT
Our client has some commands that we found were necessary for the client to have access to inside all apps. We suggest you include these in a '/command' or a '/help' command for your application in addition to your app commands
* `/list` ~ Lists all the games that are currently in the app pool
* `/launch url` ~ `url` being the address of the deployed or local app
* `/lobby` ~ Takes you back to our chat app
* `/exit` ~ Closes the rl interface and disconnects from the current application
<br>
Also, the client only listens for 'output' and 'clear' events. Keep that in mind when formatting your logic. The output event should just print the server payload, the clear will clear the console. We won't merge any client code pull requests.

#### Otherwise
You're all set to code up your app! Pay attention to comments we've implemented as you're modifying the template!

## 3. Go (Deployment)
- Runs our template server. We suggest using [nodemon]() while you're testing functionality of your app. Otherwise, everytime you make a change to your app, you have to rerun this command<br>

<span>2. Run our Hubbub Community client app =>
* `npm i -g community-hubbub`
- In case it's not already installed
* `hubbub`
- This should pull up the client
* Inside our client
* `/dev`
- Connects you to your server INSTANTLY

***Client side***<br>
<img src="./assets/Client.png" width="600px">

***Server side***<br>
<img src="./assets/server.png" width="400px">

---
## **2. Set (App logic)**

***Before you dive into any of the code, make sure to familiarize yourself with socket.io. Your server is built upon listening and emitting events to the client. The client will not work if your server doesn't work with socket.io***

### <b>IMPORTANT</b>
Our client has some commands that we found were necessary for the client to have access to inside all apps. We suggest you include these in your own `/command` or `/help` command for your application in addition to your own app commands
* `/list`
- Lists all the games that are currently in the app pool
* `/launch GAME`
- Game being one of the names from the `/list` command
* `/lobby`
- Takes you back to our chat app
* `/exit`
- Closes the rl interface and disconnects from the current application
* `/dev`
- Changes the client to direct connect to your local server ('http://localhost:4444') <br>

<b>Also,</b> the client only listens for 'output' and 'clear' events that console.log the payload. Keep that in mind when emitting events server side. The output event should just print the server payload, the clear will clear the console. We won't merge any client code pull requests. If there's a feature you want implemented, document an issue and specify a pull request for our team to consider.

### <b>OTHERWISE</b>
You're all set to code up your app! Head on over to index.js and get shnazzy! Pay attention to comments we've implemented as you're modifying the template!

---
## **3. Go (Deployment)**
So you have your awesome application, good for you! Now in order for our chat-app to include your application in our application pool, you need to send a post request to our application as described below. Here are the steps:

1. Get your server live on either heroku or azure
2. Send our chat server a post request with http
- App name ~ The name of your app
- App URL ~ URL of your live deployment
- Description ~ A short description of your app for the users to reference
* example: `echo '{"name":"YOUR_APP_NAME","url":"YOUR_APP_URL","description":"APP_DESCRIPTION"}' | http post https://shrouded-everglades-62939.herokuapp.com/api/v1/app-info`
**1.** Get your server live on either heroku or azure<br>
**2.** Update our /list with either option below<br><br>
Send our chat server a post request with httpie
- **name**
- The name of your app
- **url**
- URL of your live deployment
- **description**
- A short description of your app for the users to reference
- ***example:***

Or optionally<br>
2. Send our chat server a post request with Postman
![Postman](./assets/postman.png)
```
echo '{"name":"YOUR_APP_NAME","url":"YOUR_APP_URL","description":"APP_DESCRIPTION"}' | http post https://shrouded-everglades-62939.herokuapp.com/api/v1/app-info
```

Or Alternatively send our chat server a post request with Postman<br><br>
<img src="./assets/postmanv3.png" width="800px">

Here is a list of our API request handlers in case you need to update or change your existing application information

```
get(id) { // Gets a singular entry with the ID or all entries
return id ? this.schema.findById(id) : this.schema.find();
get(name) { // Gets a singular entry with the app name or all entries
return name ? this.schema.find({'name':name}) : this.schema.find();
}

post(obj) { //Makes a entry of your application in our list
Expand Down
Binary file added assets/Client.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/postman.png
Binary file not shown.
Binary file added assets/postmanv3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/server.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 27 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
'use strict';

const PORT = 4444;

const { phrase } = require('faker').hacker;
// KEEP THE HARD CODED PORT TO 4444
const PORT = process.env.PORT || 4444;

// `io` is your server instantiated with the port
const io = require('socket.io')(PORT);

// When sockets connect to your server
io.on('connection', socket => {
socket.emit('clear', '');
// A proof of life statement that console logs to your server terminal the socket id
console.log(`${socket.id} connected`);


//A welcome message for whoever joins
const welcome = `Hello there ${socket.id} from template server. This is a number guessing game. Guess a number between 0-9`;
socket.emit('output', welcome);

/*
The client will only emit an event('input', line), where line is what the client typed in. The client emits NO OTHER EVENTS
This is your app logic in this below function. Currently, this game is just a guessing game. Guess between a number between 1-10 You can build hangman with the client clear function to repaint the hung man and the letters. You can do a number guessing game. This is your job.
*/
socket.on('input', line => {
console.log('A line we can work with:', line);
});

setInterval(() => {
const payload = phrase();
io.emit('output', payload);
}, 1000);
console.log('User Input:', line);

const num = Math.floor(Math.random()*10);
console.log(num)
if(num == line){
socket.emit('output', 'YOU GUESSED MY NUMBER');
}
else{
socket.emit('output', 'You did not guess my number');
}
});

//Here, upon client disconnect, your server will log which socket disconnected.
socket.on('disconnect', () => {
console.log(`${socket.id} disconnected`);
});
Expand Down
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
},
"homepage": "https://github.com/node-hub/simple-app-template#readme",
"dependencies": {
"faker": "^4.1.0",
"socket.io": "^2.2.0"
}
}