Skip to content

Commit

Permalink
feat: changed backend configuring settings
Browse files Browse the repository at this point in the history
  • Loading branch information
hustle2live committed Oct 7, 2024
1 parent fbfb241 commit 31081db
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions packages/backend/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import express, { Express, Request, Response } from 'express';
import express, { Express } from 'express';
import 'dotenv/config';
import bodyParser from 'body-parser';
import cors from 'cors';
Expand All @@ -7,27 +7,27 @@ import AppRouter from './routes';

const port = process.env.PORT || 3030;

const allowAllConnections = process.env.ALLOW_ALL_CORS || false;

const app: Express = express();

const router = new AppRouter(app);

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

app.use(
cors({
origin: '*',
methods: ['POST', 'GET', 'PUT', 'DELETE'],
allowedHeaders: ['Content-type', 'Authorization'],
}),
);

app.get('/', (req: Request, res: Response) => {
res.json({ message: 'Hello Node!' });
});
if (allowAllConnections) {
app.use(
cors({
origin: '*',
methods: ['POST', 'GET', 'PUT', 'DELETE'],
allowedHeaders: ['Content-type', 'Authorization'],
}),
);
}

router.init();

app.listen(port, () => {
console.log(`Now listening on port ${port}`);
console.log(`Server is listening on port ${port}`);
});

0 comments on commit 31081db

Please sign in to comment.