Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added cors in microservice code #2

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ LOG_LEVEL=warn
DATABASE_URL=postgres://postgres:12345@localhost:5432/wa_service
RECONNECT_INTERVAL=5000
MAX_RECONNECT_RETRIES=5
AUTH_TOKEN=hello1234
AUTH_TOKEN=hello1234
CORSOPTIONS = {
origin: '*',
methods: [ 'GET', 'POST', 'PUT', 'DELETE' ],
allowedHeaders: [ 'Content-Type', 'authorization' ],
credentials: true
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@prisma/client": "^5.2.0",
"@whiskeysockets/baileys": "^6.4.1",
"baileys-bottle": "^2.1.2",
"cors": "^2.8.5",
"express": "^4.18.2",
"express-validator": "^7.0.1",
"pm2": "^5.3.0",
Expand Down
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@ import { logger, prisma } from './shared';
import messageRoutes from './router/message';
import { init } from './wa';
import { authMiddleware } from './middleware/auth-middleware';
import cors from 'cors';



const app = express();

var corsOptions : any = process.env.CORSOPTIONS ||
{
origin: '*',
methods: [ 'GET', 'POST', 'PUT', 'DELETE' ],
allowedHeaders: [ 'Content-Type', 'authorization' ],
credentials: true
};

app.use(cors(corsOptions));
app.use(bodyParser.json());
app.use(authMiddleware)
app.use('/session',sessionRouter);
Expand Down
12 changes: 10 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,14 @@ [email protected]:
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.5.0.tgz#d1f5d71adec6558c58f389987c366aa47e994f8b"
integrity sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==

cors@^2.8.5:
version "2.8.5"
resolved "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz"
integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==
dependencies:
object-assign "^4"
vary "^1"

croner@~4.1.92:
version "4.1.97"
resolved "https://registry.yarnpkg.com/croner/-/croner-4.1.97.tgz#6e373dc7bb3026fab2deb0d82685feef20796766"
Expand Down Expand Up @@ -1774,7 +1782,7 @@ [email protected]:
eventemitter2 "~0.4.14"
lazy "~1.0.11"

object-assign@^4.0.1:
object-assign@^4, object-assign@^4.0.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
integrity sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==
Expand Down Expand Up @@ -2625,7 +2633,7 @@ validator@^13.9.0:
resolved "https://registry.yarnpkg.com/validator/-/validator-13.11.0.tgz#23ab3fd59290c61248364eabf4067f04955fbb1b"
integrity sha512-Ii+sehpSfZy+At5nPdnyMhx78fEoPDkR2XW/zimHEL3MyGJQOCQ7WeP20jPYRz7ZCpcKLB21NxuXHF3bxjStBQ==

vary@~1.1.2:
vary@^1, vary@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==
Expand Down