summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2019-08-03 20:50:04 -0700
committerPhilip Chimento <philip.chimento@gmail.com>2019-08-13 22:17:34 -0700
commita7954ac92eece34ace702b397f3e981933e7e346 (patch)
tree8aa6a9596f56adfafb3fcdf212707157932bac79 /examples
parent57016a3c97f40fad2c4713f8ffcd835fae9e304d (diff)
downloadgjs-a7954ac92eece34ace702b397f3e981933e7e346.tar.gz
CI: Add func-style to eslint rules
function foo() { ... } is shorter than var foo = function() { ... };, and there's also less chance to have a discrepancy between the names of the function and the variable holding it.
Diffstat (limited to 'examples')
-rw-r--r--examples/http-server.js48
1 files changed, 33 insertions, 15 deletions
diff --git a/examples/http-server.js b/examples/http-server.js
index cbc6a75a..0e8aede2 100644
--- a/examples/http-server.js
+++ b/examples/http-server.js
@@ -2,23 +2,41 @@
const Soup = imports.gi.Soup;
-function main() {
- let handler = function(server, msg, path, query, client) {
- msg.status_code = 200;
- msg.response_headers.set_content_type('text/html', {});
- msg.response_body.append(`<html><body>Greetings, visitor from ${client.get_host()}<br>What is your name?<form action="/hello"><input name="myname"></form></body></html>\n`);
- };
- let helloHandler = function(server, msg, path, query) {
- if (!query) {
- msg.set_redirect(302, '/');
- return;
- }
+function handler(server, msg, path, query, client) {
+ msg.status_code = 200;
+ msg.response_headers.set_content_type('text/html', {});
+ msg.response_body.append(`
+ <html>
+ <body>
+ Greetings, visitor from ${client.get_host()}<br>
+ What is your name?
+ <form action="/hello">
+ <input name="myname">
+ </form>
+ </body>
+ </html>
+ `);
+}
- msg.status_code = 200;
- msg.response_headers.set_content_type('text/html', {charset: 'UTF-8'});
- msg.response_body.append(`<html><body>Hello, ${query.myname}! ☺<br><a href="/">Go back</a></body></html>`);
- };
+function helloHandler(server, msg, path, query) {
+ if (!query) {
+ msg.set_redirect(302, '/');
+ return;
+ }
+ msg.status_code = 200;
+ msg.response_headers.set_content_type('text/html', {charset: 'UTF-8'});
+ msg.response_body.append(`
+ <html>
+ <body>
+ Hello, ${query.myname}! ☺<br>
+ <a href="/">Go back</a>
+ </body>
+ </html>
+ `);
+}
+
+function main() {
let server = new Soup.Server({port: 1080});
server.add_handler('/', handler);
server.add_handler('/hello', helloHandler);