mirror of
https://github.com/SrIzan10/starters.git
synced 2026-05-01 11:05:16 +00:00
Update expressjs-prisma example (#69)
* add slack webhook example * update expressjs-prisma starter
This commit is contained in:
@@ -8,18 +8,17 @@
|
||||
"dev": "nodemon src/index.ts",
|
||||
"build": "yarn migrate:deploy && tsc",
|
||||
"start": "node dist/index.js",
|
||||
"migrate:dev": "prisma migrate dev --preview-feature",
|
||||
"migrate:deploy": "prisma migrate deploy --preview-feature",
|
||||
"migrate:status": "prisma migrate status --preview-feature",
|
||||
"migrate:dev": "prisma migrate dev",
|
||||
"migrate:deploy": "prisma migrate deploy",
|
||||
"migrate:status": "prisma migrate status",
|
||||
"generate": "prisma generate"
|
||||
},
|
||||
"dependencies": {
|
||||
"@prisma/client": "2.15.0",
|
||||
"body-parser": "^1.19.0",
|
||||
"@prisma/client": "2.20.0",
|
||||
"express": "^4.17.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@prisma/cli": "2.15.0",
|
||||
"prisma": "2.20.0",
|
||||
"@types/body-parser": "^1.19.0",
|
||||
"@types/express": "^4.17.11",
|
||||
"@types/node": "^14.14.22",
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import bodyParser from "body-parser";
|
||||
import express from "express";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
@@ -7,9 +6,9 @@ const prisma = new PrismaClient();
|
||||
const app = express();
|
||||
const port = process.env.PORT || 3000;
|
||||
|
||||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.raw({ type: "application/vnd.custom-type" }));
|
||||
app.use(bodyParser.text({ type: "text/html" }));
|
||||
app.use(express.json());
|
||||
app.use(express.raw({ type: "application/vnd.custom-type" }));
|
||||
app.use(express.text({ type: "text/html" }));
|
||||
|
||||
app.get("/todos", async (req, res) => {
|
||||
const todos = await prisma.todo.findMany({
|
||||
|
||||
@@ -2,29 +2,22 @@
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@prisma/cli@2.15.0":
|
||||
version "2.15.0"
|
||||
resolved "https://registry.yarnpkg.com/@prisma/cli/-/cli-2.15.0.tgz#a979a67dbd606a966cf475686170128562590713"
|
||||
integrity sha512-sF2mgn5oH5fL9/CKxS0tqojf0rK2BKODlEUqL+2s3YZqvJRSt4iFpiyjgajyd0wyTyv1k9LDHTV0yOD1mXDBsA==
|
||||
"@prisma/client@2.20.0":
|
||||
version "2.20.0"
|
||||
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-2.20.0.tgz#056ed756c2ea536b87771e79f68a984e94a452d8"
|
||||
integrity sha512-WnYFD7JVs4nFyJyvOZc/fRQ6G+yLEXeANElX70hLlGHvi6YiruTDCXs/nryO8pTzdhg3//+ZynCvV+WHxV+sFg==
|
||||
dependencies:
|
||||
"@prisma/engines" "2.15.0-25.e51dc3b5a9ee790a07104bec1c9477d51740fe54"
|
||||
"@prisma/engines-version" "2.20.0-26.60ba6551f29b17d7d6ce479e5733c70d9c00860e"
|
||||
|
||||
"@prisma/client@2.15.0":
|
||||
version "2.15.0"
|
||||
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-2.15.0.tgz#41ee22c60778b54aec0f6d4832c2d35fbf9eb423"
|
||||
integrity sha512-3j4OoLpAGF104KAenUFJM9sU2+4jRP+RlrlYssBHkwBf+/5+2ihSpcmFiWIw1vXNRdmZtivjwhjcVtmjZPJktw==
|
||||
dependencies:
|
||||
"@prisma/engines-version" "2.15.0-25.e51dc3b5a9ee790a07104bec1c9477d51740fe54"
|
||||
"@prisma/engines-version@2.20.0-26.60ba6551f29b17d7d6ce479e5733c70d9c00860e":
|
||||
version "2.20.0-26.60ba6551f29b17d7d6ce479e5733c70d9c00860e"
|
||||
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-2.20.0-26.60ba6551f29b17d7d6ce479e5733c70d9c00860e.tgz#1189f0a7e682f500015446cfe2b34d2753452190"
|
||||
integrity sha512-fJhbGZXm2SPs/RsI79Ew4SFe+6QmChNdgU2I/SIjmU18bUgK8f1TBEWnVtFdBqEDHYPGxbpaianF7lp04KN7EA==
|
||||
|
||||
"@prisma/engines-version@2.15.0-25.e51dc3b5a9ee790a07104bec1c9477d51740fe54":
|
||||
version "2.15.0-25.e51dc3b5a9ee790a07104bec1c9477d51740fe54"
|
||||
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-2.15.0-25.e51dc3b5a9ee790a07104bec1c9477d51740fe54.tgz#d9c887bc8f30d1f107c9021b2565a8672d62622d"
|
||||
integrity sha512-KDxk7Zsc9tDoShCE7v+O1SnCUTUkMdfezjbuz9CBvdEBGMtYLgyHaZAO8M038uqy8KjgwV9PzyoLqvVfzfsngg==
|
||||
|
||||
"@prisma/engines@2.15.0-25.e51dc3b5a9ee790a07104bec1c9477d51740fe54":
|
||||
version "2.15.0-25.e51dc3b5a9ee790a07104bec1c9477d51740fe54"
|
||||
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-2.15.0-25.e51dc3b5a9ee790a07104bec1c9477d51740fe54.tgz#3093ace7c09cf694214727c4e67109f2a2d8855a"
|
||||
integrity sha512-AgPxAWtwYhhTNEEsV4lK63HTe9z0GAGL3ofMr2B0TncACmzi9lhdun9TTNie38Oy/3DLfr71TUHKUpV8QjOKUw==
|
||||
"@prisma/engines@2.20.0-26.60ba6551f29b17d7d6ce479e5733c70d9c00860e":
|
||||
version "2.20.0-26.60ba6551f29b17d7d6ce479e5733c70d9c00860e"
|
||||
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-2.20.0-26.60ba6551f29b17d7d6ce479e5733c70d9c00860e.tgz#18f23c4a8a335a93fd338f88c310f5cf120f5591"
|
||||
integrity sha512-zOWETm7DTRvlwf/CekPNSeJe6EC5bn2IFexd74wM9zgBXCZo+1sMDuNGtCqIt4Rzv8CcimEgyzrEFVq0LPV8qg==
|
||||
|
||||
"@sindresorhus/is@^0.14.0":
|
||||
version "0.14.0"
|
||||
@@ -165,7 +158,7 @@ binary-extensions@^2.0.0:
|
||||
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d"
|
||||
integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==
|
||||
|
||||
body-parser@1.19.0, body-parser@^1.19.0:
|
||||
body-parser@1.19.0:
|
||||
version "1.19.0"
|
||||
resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.19.0.tgz#96b2709e57c9c4e09a6fd66a8fd979844f69f08a"
|
||||
integrity sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==
|
||||
@@ -915,6 +908,13 @@ prepend-http@^2.0.0:
|
||||
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897"
|
||||
integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=
|
||||
|
||||
prisma@2.20.0:
|
||||
version "2.20.0"
|
||||
resolved "https://registry.yarnpkg.com/prisma/-/prisma-2.20.0.tgz#3b7562326f764b4785e92bc83741b91ff2264be7"
|
||||
integrity sha512-z8zCFxOA4rVy49GHzxx886dDMTmM3oh6GPRvatujshTqJeD+znJS4sxekVfjmTp0zX1aO92wBd3J6yon5DE1jg==
|
||||
dependencies:
|
||||
"@prisma/engines" "2.20.0-26.60ba6551f29b17d7d6ce479e5733c70d9c00860e"
|
||||
|
||||
proxy-addr@~2.0.5:
|
||||
version "2.0.6"
|
||||
resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-2.0.6.tgz#fdc2336505447d3f2f2c638ed272caf614bbb2bf"
|
||||
|
||||
30
examples/slack-webhook/.gitignore
vendored
Normal file
30
examples/slack-webhook/.gitignore
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# local env files
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
# out dir
|
||||
dist/
|
||||
25
examples/slack-webhook/README.md
Normal file
25
examples/slack-webhook/README.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Slack webhook starter
|
||||
|
||||
This example starts an [ExpressJS](https://expressjs.com/) server containing a post request to emit a message on Slack.
|
||||
|
||||
[](https://railway.app/new?template=https%3A%2F%2Fgithub.com%2Frailwayapp%2Fstarters%2Ftree%2Fmaster%2Fexamples%2Fslack-webhook&envs=SLACK_WEBHOOK_URL)
|
||||
|
||||
## ✨ Features
|
||||
|
||||
- Express
|
||||
- TypeScript
|
||||
- Slack webhook route
|
||||
|
||||
## 💁♀️ How to use
|
||||
|
||||
- Create a Slack app with an [incoming webhook](https://api.slack.com/messaging/webhooks).
|
||||
- Click the deploy button and add the `SLACK_WEBHOOK_URL`.
|
||||
- Install dependencies `yarn`
|
||||
- Connect to your Railway project `railway init`
|
||||
- Start the development server `railway run yarn dev`
|
||||
|
||||
## 📝 Notes
|
||||
|
||||
The server started simply returns `Hello from the webhook! :rocket:`. You can consume whatever information you'd like from your custom webhook, parse it and send it to Slack accordingly.
|
||||
|
||||
You can read the documentation for formatting your messages [here](https://api.slack.com/reference/surfaces/formatting).
|
||||
25
examples/slack-webhook/package.json
Normal file
25
examples/slack-webhook/package.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "slack-webhook",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"author": "Faraz Patankar",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"dev": "nodemon src/index.ts",
|
||||
"build": "tsc",
|
||||
"start": "node dist/index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.21.1",
|
||||
"express": "^4.17.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/body-parser": "^1.19.0",
|
||||
"@types/express": "^4.17.11",
|
||||
"@types/node": "^14.14.22",
|
||||
"nodemon": "^2.0.7",
|
||||
"ts-node": "^9.1.1",
|
||||
"typescript": "^4.1.3"
|
||||
}
|
||||
}
|
||||
46
examples/slack-webhook/src/index.ts
Normal file
46
examples/slack-webhook/src/index.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import express from "express";
|
||||
import axios from "axios";
|
||||
|
||||
const app = express();
|
||||
const port = process.env.PORT || 3333;
|
||||
|
||||
app.use(express.json());
|
||||
app.use(express.raw({ type: "application/vnd.custom-type" }));
|
||||
app.use(express.text({ type: "text/html" }));
|
||||
|
||||
app.get("/", async (req, res) => {
|
||||
res.json({ Hello: "World" });
|
||||
});
|
||||
|
||||
app.post("/webhook", async (req, res) => {
|
||||
/*
|
||||
SLACK_WEBHOOK_URL is an environment variable
|
||||
that should be configured on Railway
|
||||
*/
|
||||
if (!process.env.SLACK_WEBHOOK_URL) {
|
||||
res.status(500).json("Please add a Slack webhook URL");
|
||||
return;
|
||||
}
|
||||
|
||||
const body = JSON.stringify({ text: "Hello from the webhook! :rocket:" });
|
||||
|
||||
try {
|
||||
const response = await axios.post(process.env.SLACK_WEBHOOK_URL, body, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
res.sendStatus(response.status);
|
||||
} catch (error) {
|
||||
console.error("error", error.response.data);
|
||||
console.error("error", error.response.status);
|
||||
console.error("error", error.response.headers);
|
||||
|
||||
res.sendStatus(error.response.status);
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Example app listening at http://localhost:${port}`);
|
||||
});
|
||||
13
examples/slack-webhook/tsconfig.json
Normal file
13
examples/slack-webhook/tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
|
||||
"incremental": true,
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
}
|
||||
}
|
||||
1278
examples/slack-webhook/yarn.lock
Normal file
1278
examples/slack-webhook/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user