Skip to content

Commit 61160a4

Browse files
committed
Fix code style with prettier
1 parent 60d4eb5 commit 61160a4

File tree

5 files changed

+844
-425
lines changed

5 files changed

+844
-425
lines changed

express/README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
httpsms-express
2-
===============
1+
# httpsms-express
32

43
[![Build](https://github.com/NdoleStudio/httpsms-recipes/actions/workflows/ci.yml/badge.svg)](https://github.com/NdoleStudio/httpsms-recipes/actions/workflows/ci.yml)
54
[![GitHub contributors](https://img.shields.io/github/contributors/NdoleStudio/httpsms-recipes)](https://github.com/NdoleStudio/httpsms-recipes/graphs/contributors)
65
[![GitHub license](https://img.shields.io/github/license/NdoleStudio/httpsms-recipes?color=brightgreen)](https://github.com/NdoleStudio/httpsms-recipes/blob/master/LICENSE)
76

8-
This recipe contains an example express.js application to receive incoming webhook events from the httpsms.com API.
7+
This recipe contains an example express.js application to receive incoming webhook events from the httpsms.com API.
98
You can use this code as inspiration for creating a consumer for webhook events from httpsms.com.
109

1110
## Documentation
@@ -17,7 +16,6 @@ httpSMS webhook documentation: https://docs.httpsms.com/webhooks/introduction
1716
- [express 4.x](https://expressjs.com/) - Express framework
1817
- [jsonwebtoken](https://github.com/auth0/node-jsonwebtoken) - Used to authenticate webhook requests.
1918

20-
2119
## Architecture
2220

2321
The `/httpsms/webhook` endpoint authenticates webhook requests from httpSMS using the `Bearer` JWT token.
@@ -41,10 +39,9 @@ ngrok http localhost:3000
4139
Now configure your webhook endpoint https://httpsms.com/settings to point to the URL provided by ngrok.
4240
When you receive an SMS, you will see the logs in your terminal as shown in the image below.
4341

44-
4542
## Security Vulnerabilities
4643

47-
If you discover a security vulnerability within the dompdf-api service, please send an e-mail to Acho Arnold via
44+
If you discover a security vulnerability within the dompdf-api service, please send an e-mail to Acho Arnold via
4845
[[email protected]](mailto:[email protected]). All security vulnerabilities will be promptly addressed.
4946

5047
## License

express/app.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,57 @@
1-
const express = require('express');
2-
const logger = require('morgan');
3-
const httpsms = require('fix-esm').require('httpsms');
4-
const jwt = require('jsonwebtoken');
1+
const express = require("express");
2+
const logger = require("morgan");
3+
const httpsms = require("fix-esm").require("httpsms");
4+
const jwt = require("jsonwebtoken");
55

66
const app = express();
77

8-
app.use(logger('dev'));
8+
app.use(logger("dev"));
99
app.use(express.json());
1010

11-
app.get('/', (request, response) => {
12-
response.status(200).json({ status: 'ok' });
11+
app.get("/", (request, response) => {
12+
response.status(200).json({ status: "ok" });
1313
});
1414

1515
// Webhook endpoint to receive incoming messages
16-
app.post('/httpsms/webhook', (request, response) => {
16+
app.post("/httpsms/webhook", (request, response) => {
1717
// Verify auth token
1818
if (process.env.HTTPSMS_WEBHOOK_SIGNING_KEY) {
1919
try {
20-
const token = request.header('Authorization').replace("Bearer ", "");
20+
const token = request.header("Authorization").replace("Bearer ", "");
2121
const claims = jwt.verify(token, process.env.HTTPSMS_WEBHOOK_SIGNING_KEY);
22-
console.info('Authorization token verified from httpsms.com');
22+
console.info("Authorization token verified from httpsms.com");
2323
console.debug(JSON.stringify(claims, null, 2));
2424
} catch (error) {
25-
console.error('Invalid Authorization token', error);
26-
return response.status(401).json({ error: 'Unauthorized' });
25+
console.error("Invalid Authorization token", error);
26+
return response.status(401).json({ error: "Unauthorized" });
2727
}
2828
}
2929

3030
const event = request.body;
31-
console.info(`httpsms.com webhook event received with type [${request.header('X-Event-Type')}]`);
31+
console.info(
32+
`httpsms.com webhook event received with type [${request.header("X-Event-Type")}]`,
33+
);
3234
console.info(`decoded [${event.type}] with id [${event.id}`);
3335
console.debug(JSON.stringify(event.data, null, 2));
3436

35-
response.json({ status: 'success' });
37+
response.json({ status: "success" });
3638
});
3739

38-
3940
// Send a sample text message
40-
app.get('/httpsms/send', async (request, response) => {
41-
const httpsmsClient = new httpsms('' /* Get the API Key from https://httpsms.com/settings */);
41+
app.get("/httpsms/send", async (request, response) => {
42+
const httpsmsClient = new httpsms(
43+
"" /* Get the API Key from https://httpsms.com/settings */,
44+
);
4245

4346
const message = await httpsmsClient.messages.postSend({
44-
content: 'This is a sample text message',
45-
from: '+18005550199', // Put the correct phone number here
46-
to: '+18005550100', // Put the correct phone number here
47+
content: "This is a sample text message",
48+
from: "+18005550199", // Put the correct phone number here
49+
to: "+18005550100", // Put the correct phone number here
4750
encrypted: false,
48-
})
51+
});
4952

5053
console.info(`message sent successfully with ID [${message.id}]`);
51-
response.status(200).json({ status: 'ok' });
54+
response.status(200).json({ status: "ok" });
5255
});
5356

54-
55-
5657
module.exports = app;

express/bin/www

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
#!/usr/bin/env node
22

3-
process.removeAllListeners('warning')
3+
process.removeAllListeners("warning");
44

55
/**
66
* Module dependencies.
77
*/
88

9-
var app = require('../app');
10-
var debug = require('debug')('express:server');
11-
var http = require('http');
9+
var app = require("../app");
10+
var debug = require("debug")("express:server");
11+
var http = require("http");
1212

1313
/**
1414
* Get port from environment and store in Express.
1515
*/
1616

17-
var port = normalizePort(process.env.PORT || '3000');
18-
app.set('port', port);
17+
var port = normalizePort(process.env.PORT || "3000");
18+
app.set("port", port);
1919

2020
/**
2121
* Create HTTP server.
@@ -28,8 +28,8 @@ var server = http.createServer(app);
2828
*/
2929

3030
server.listen(port);
31-
server.on('error', onError);
32-
server.on('listening', onListening);
31+
server.on("error", onError);
32+
server.on("listening", onListening);
3333

3434
/**
3535
* Normalize a port into a number, string, or false.
@@ -56,22 +56,20 @@ function normalizePort(val) {
5656
*/
5757

5858
function onError(error) {
59-
if (error.syscall !== 'listen') {
59+
if (error.syscall !== "listen") {
6060
throw error;
6161
}
6262

63-
var bind = typeof port === 'string'
64-
? 'Pipe ' + port
65-
: 'Port ' + port;
63+
var bind = typeof port === "string" ? "Pipe " + port : "Port " + port;
6664

6765
// handle specific listen errors with friendly messages
6866
switch (error.code) {
69-
case 'EACCES':
70-
console.error(bind + ' requires elevated privileges');
67+
case "EACCES":
68+
console.error(bind + " requires elevated privileges");
7169
process.exit(1);
7270
break;
73-
case 'EADDRINUSE':
74-
console.error(bind + ' is already in use');
71+
case "EADDRINUSE":
72+
console.error(bind + " is already in use");
7573
process.exit(1);
7674
break;
7775
default:
@@ -85,8 +83,6 @@ function onError(error) {
8583

8684
function onListening() {
8785
var addr = server.address();
88-
var bind = typeof addr === 'string'
89-
? 'pipe ' + addr
90-
: 'port ' + addr.port;
91-
debug('Listening on ' + bind);
86+
var bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port;
87+
debug("Listening on " + bind);
9288
}

express/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@
1313
"httpsms": "^0.0.4",
1414
"jsonwebtoken": "^9.0.2",
1515
"morgan": "~1.10.0"
16+
},
17+
"devDependencies": {
18+
"prettier": "^3.3.3"
1619
}
1720
}

0 commit comments

Comments
 (0)