-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathapp.js
More file actions
28 lines (23 loc) · 687 Bytes
/
Copy pathapp.js
File metadata and controls
28 lines (23 loc) · 687 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const express = require("express");
const removespace = require("../index");
const app = express();
app.use(express.json());
app.get("/", (req, res) => {
res.json({ message: "Hello from the Node.js Example API!" });
});
app.get("/health", (req, res) => {
res.json({ status: "healthy" });
});
app.post("/removespace", (req, res) => {
const { text } = req.body;
if (text === undefined) {
return res.status(400).json({ error: "Missing 'text' field in request body" });
}
try {
const result = removespace(text);
return res.json({ original: text, result });
} catch (err) {
return res.status(400).json({ error: err.message });
}
});
module.exports = app;