Skip to content

Commit

Permalink
Merge pull request agiledev-students-fall2023#206 from agiledev-stude…
Browse files Browse the repository at this point in the history
…nts-fall2023/Ceiceiceii-patch-1

Update app.mjs
  • Loading branch information
Ceiceiceii authored Jan 6, 2024
2 parents dfbe6ba + c814c36 commit 10b0037
Showing 1 changed file with 0 additions and 94 deletions.
94 changes: 0 additions & 94 deletions back-end/src/app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -127,97 +127,3 @@ app.get('/searchArts', searchArtsRouter);
app.get('/getBorder', getBorderRouter);
// export the express app we created to make it available to other modules
export default app;



// serve static files
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
app.use("/static", express.static(path.join(__dirname, 'dist')));
dotenv.config({ path: path.resolve(__dirname, '../.env') });

// cors
const corsOptions = {
credentials: true,
origin: process.env.CLIENT_URL.replace(/\/$/, ""),
// origin: 'http://10.19.137.49:5173/',
methods: ["GET", "PUT", "POST", "DELETE", "PATCH"],
};
app.use(cors(corsOptions));


// console.log("MongoDB URI: ", process.env.MONGODB_URI);




console.log(process.env.CLIENT_URL);
// Connect to MongoDB
mongoose.connect(process.env.MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => {
console.log('Connected to MongoDB...');
})
.catch(err => console.error('Could not connect to MongoDB...', err));


// Validation rules for routers
const usernameValidationRules = [
body("newUsername")
.trim() // Removes leading and trailing spaces
.isLength({ min: 3, max: 30 }) // Sets a length range for the username
.withMessage("Username must be between 3 and 30 characters long.")
.matches(/^[a-zA-Z0-9_]+$/) // Regular expression to allow letters, numbers, and underscores
.withMessage(
"Username must contain only letters, numbers, and underscores."
),
];
const emailValidationRules = [
body("newEmail")
.trim() // Removes leading and trailing spaces
.isEmail() // Checks if the input is an email
.withMessage("Please enter a valid email address.")
.normalizeEmail(), // Optionally, normalize the email address
];
const passwordValidationRules = [
// Validate new password
body("newPassword")
.isLength({ min: 8 }) // Set a minimum length for the new password
.withMessage("Password must be at least 8 characters long")
.matches(/\d/) // Ensure the password contains a number
.withMessage("Password must contain at least one number")
.matches(/[a-zA-Z]/) // Ensure the password contains a letter
.withMessage("Password must contain at least one letter"),
// Optionally, include checks for special characters or uppercase letters
];


// jwt strategy
passport.use(JwtStrategy)
app.use(passport.initialize())

// Authenticate private routes
// app.use("/auth", passport.authenticate('jwt', { session: false }))

// Favorites list routes
app.get("/getArts", getArts); //finished
app.get("/searchArts", searchArtsRouter);
app.post("/auth/addFavorite", addFavListRouter); //finished
app.get("/auth/getfavlist", favListRouter);

// Account routes
app.post("/register", registerRouter);
app.post("/login", loginRouter);
app.patch("/auth/changeusername", usernameValidationRules, changeusernameRouter); //Finished
app.patch("/auth/resetemail", emailValidationRules, resetemailRouter); //Finished
app.post("/auth/forgetpassword", forgetpasswordRouter);
app.patch("/auth/resetpassword", passwordValidationRules, resetpasswordRouter); //Finished
app.delete("/auth/delaccount", delaccountRouter); //Finished

return app;
}

// app.post('/favlist/remove',removeFavListRouter);


app.get('/getBorder', getBorderRouter);
// export the express app we created to make it available to other modules
// export default app;

0 comments on commit 10b0037

Please sign in to comment.