1
0
mirror of https://api.glitch.com/git/presence-button synced 2024-11-05 08:27:29 +00:00

🏏🍱 Checkpoint

./package.json:933874/347
./server.js:933874/577
./views/index.html:933874/979
This commit is contained in:
Glitch (hello-express) 2019-11-03 11:22:00 +00:00
parent 30930b4ced
commit 752427dec7
4 changed files with 22 additions and 72 deletions

View File

@ -1,10 +1,7 @@
{ {
"//1": "describes your app and its dependencies", "name": "presence-button",
"//2": "https://docs.npmjs.com/files/package.json",
"//3": "updating this file will download and update your packages",
"name": "hello-express",
"version": "0.0.1", "version": "0.0.1",
"description": "A simple Node app built on Express, instantly up and running.", "description": "Always-up server for Fuz presence button",
"main": "server.js", "main": "server.js",
"scripts": { "scripts": {
"start": "node server.js" "start": "node server.js"
@ -16,12 +13,11 @@
"node": "8.x" "node": "8.x"
}, },
"repository": { "repository": {
"url": "https://glitch.com/edit/#!/hello-express" "url": "https://glitch.com/edit/#!/presence-button"
}, },
"license": "MIT", "license": "MIT",
"keywords": [ "keywords": [
"node", "node",
"glitch",
"express" "express"
] ]
} }

View File

@ -1,42 +0,0 @@
// client-side js
// run by the browser each time your view template is loaded
console.log("hello world :o");
// our default array of dreams
const dreams = [
"Find and count some sheep",
"Climb a really tall mountain",
"Wash the dishes"
];
// define variables that reference elements on our page
const dreamsList = document.getElementById("dreams");
const dreamsForm = document.forms[0];
const dreamInput = dreamsForm.elements["dream"];
// a helper function that creates a list item for a given dream
const appendNewDream = function(dream) {
const newListItem = document.createElement("li");
newListItem.innerHTML = dream;
dreamsList.appendChild(newListItem);
};
// iterate through every dream and add it to our page
dreams.forEach(function(dream) {
appendNewDream(dream);
});
// listen for the form to be submitted and add a new dream when it is
dreamsForm.onsubmit = function(event) {
// stop our form submission from refreshing the page
event.preventDefault();
// get dream value and add it to the list
dreams.push(dreamInput.value);
appendNewDream(dreamInput.value);
// reset form
dreamInput.value = "";
dreamInput.focus();
};

View File

@ -1,13 +1,6 @@
// server.js
// where your node app starts
// init project
const express = require("express"); const express = require("express");
const app = express(); const app = express();
// we've started you off with Express,
// but feel free to use whatever libs or frameworks you'd like through `package.json`.
// http://expressjs.com/en/starter/static-files.html // http://expressjs.com/en/starter/static-files.html
app.use(express.static("public")); app.use(express.static("public"));
@ -16,7 +9,16 @@ app.get("/", function(request, response) {
response.sendFile(__dirname + "/views/index.html"); response.sendFile(__dirname + "/views/index.html");
}); });
// listen for requests :) // http://expressjs.com/en/starter/basic-routing.html
app.get("/img", function(request, response) {
response.sendFile(__dirname + "/views/index.html");
});
const listener = app.listen(process.env.PORT, function() { const listener = app.listen(process.env.PORT, function() {
console.log("Your app is listening on port " + listener.address().port); console.log("Your app is listening on port " + listener.address().port);
}); });
process.on("SIGTERM", function () {
console.log("SIGTERM received, sending SOS to Resurrect...");
require('https').get("https://resurrect.glitch.me/"+process.env.PROJECT_DOMAIN+"", process.exit)
});

View File

@ -10,38 +10,32 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<title>Welcome to Glitch!</title> <title>Fuz presence button</title>
<meta name="description" content="A cool thing made with Glitch"> <meta name="description" content="Public API for Fuz hackerspace presence button">
<link id="favicon" rel="icon" href="https://glitch.com/edit/favicon-app.ico" type="image/x-icon"> <link id="favicon" rel="icon" href="https://fuz.frama.site/medias/5c02ae843c25e.jpg" type="image/x-icon">
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<!-- import the webpage's stylesheet --> <!-- import the webpage's stylesheet -->
<link rel="stylesheet" href="/style.css"> <link rel="stylesheet" href="/style.css">
<!-- import the webpage's client-side javascript file -->
<script src="/client.js" defer></script>
</head> </head>
<body> <body>
<header> <header>
<h1> <h1>
A Dream of the Future Fuz presence button public API
</h1> </h1>
</header> </header>
<main> <main>
<p class="bold">Oh hi,</p>
<p>Tell me your hopes and dreams:</p> <p>See documentation for this project on <a href="https://wiki.fuz.re/doku.php?id=projets:fuz:presence_button">Fuz wiki</a>:</p>
<form>
<input name="dream" type="text" maxlength="100" placeholder="Dreams!" aria-labelledby="submit-dream">
<button type="submit" id="submit-dream">Submit Dream</button>
</form>
<section class="dreams"> <section class="dreams">
<ul id="dreams"></ul> <ul id="dreams">
<li><a href="/img">image API</a></li>
<li><a href="/api">ajax API</a></li>
</ul>
</section> </section>
</main> </main>