Skip to content

Commit

Permalink
Clear table for express-postgres
Browse files Browse the repository at this point in the history
Adds ability to clear table contents with a single click
  • Loading branch information
npu authored Mar 8, 2024
1 parent a949ac9 commit 591bc4c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sample-apps/express-postgres/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function getHTMLBody(cats) {
<input type="text" name="petname">
<input type="submit" value="Add" />
</form>
<a href="http://localhost:4000/?petname=Kitty'); DELETE FROM cats;-- H">Test injection</a>
<a href="http://localhost:4000/?petname=Kitty'); DELETE FROM cats;-- H">Test injection</a> / <a href="http://localhost:4000/clear">Clear table</a>
</body>
</html>`;
}
Expand Down Expand Up @@ -64,6 +64,11 @@ async function main(port) {
})
);

app.get("/clear", asyncHandler(async (req, res) => {
await db.query("DELETE FROM cats;");
res.redirect("/");
}));

return new Promise((resolve, reject) => {
try {
app.listen(port, () => {
Expand Down

0 comments on commit 591bc4c

Please sign in to comment.