Skip to content
This repository has been archived by the owner on Jan 31, 2025. It is now read-only.

Commit

Permalink
finished noAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
abdinasir-Tman committed Feb 3, 2024
1 parent a3d8f27 commit c5da5d6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,20 @@ import { rateLimit } from "express-rate-limit";
import helmet from "helmet";
import morgan from "morgan";

import userRouter from "./routes/user.router.js";
import AppDataSource from "./config/db.config.js";

AppDataSource.initialize()
.then(() => {
console.log(`${chalk.green.bold("Connected")} to the database ✅`);
const PORT = port;

const app = express();

app.use(morgan("dev"));

var whitelist = ["http://localhost:8000"];

var corsOptionsDelegate = function (req, callback) {
var corsOptions;
if (whitelist.indexOf(req.header("Origin")) !== -1) {
corsOptions = { origin: true };
} else {
corsOptions = { origin: false };
}
callback(null, corsOptions);
};

app.use(cors(corsOptionsDelegate));
app.use(express.json());
app.use(helmet());
app.use(cookieParser());

const apiRateLimit = rateLimit({
windowMs: 15 * 60 * 1000,
max: 10,
message: "Rate limit exceeded",
});

app.use(apiRateLimit);

// route management
app.use("/api/v1/users", userRouter);

app.listen(PORT, () => {
console.log(process.env.PORT);
console.log(
`${chalk.green.bold("Server")} is listening on port ${chalk.green.bold(
PORT
)} 🚀`
);
});
})
.catch((err) => {
console.log(`${chalk.red.bold("Error")} connecting to database`, err);
});
import routerName from "./routes/router.js";

const PORT = port;
const app = express();

app.use(express.json());
app.use("/api/v1/", routerName);

app.listen(PORT, () => {
console.log(process.env.PORT);
console.log(
`${chalk.green.bold("Server")} is listening on port ${chalk.green.bold(
PORT
)} 🚀`
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ const AppDataSource = new DataSource({
database: "yonode",
// entities: [User],
synchronize: true,
useUnifiedTopology: true,
});
AppDataSource.initialize()
.then(async () => {
console.log("database connected");
console.log("Data Source has been initialized!");
console.log(`${chalk.green.bold("Connected")} to the database ✅`);
})
.catch((error) => console.log(error));
export default AppDataSource;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express from "express";
import { controlerName } from "../controllers/user.controller.js";
import { controlerName } from "../controllers/controller.js";

const routerName = express.Router();

Expand Down

0 comments on commit c5da5d6

Please sign in to comment.