more bug fix, fix to run on fly.io
This commit is contained in:
parent
aded70ea0b
commit
330baa51ac
16 changed files with 529 additions and 150 deletions
23
auth-service/routes/api.js
Normal file
23
auth-service/routes/api.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
const { createProxyMiddleware } = require("http-proxy-middleware");
|
||||
const api = require("express").Router();
|
||||
|
||||
const ASSIGNMENT_SERVICE_URL = process.env.ASSIGNMENT_SERVICE_URL;
|
||||
|
||||
// rerout to asisgnment url
|
||||
api.use((req, res, next) => {
|
||||
console.log(`Proxying request to: ${ASSIGNMENT_SERVICE_URL} : original url : ${req.originalUrl}`);
|
||||
next();
|
||||
});
|
||||
|
||||
api.use(
|
||||
'/',
|
||||
createProxyMiddleware({
|
||||
target: ASSIGNMENT_SERVICE_URL,
|
||||
changeOrigin: true,
|
||||
pathRewrite: {
|
||||
'^/api': '', // only remove /api
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
module.exports = api;
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
const router = require("express").Router();
|
||||
const auth = require("express").Router();
|
||||
const passport = require("passport");
|
||||
const axios = require("axios");
|
||||
|
||||
const AUTH_URL = process.env.AUTH_URL || "http://localhost:8080";
|
||||
|
||||
router.get(
|
||||
auth.get(
|
||||
"/google/callback",
|
||||
passport.authenticate("google", {
|
||||
failureRedirect: "/auth/login/failed",
|
||||
|
|
@ -41,7 +41,7 @@ router.get(
|
|||
}
|
||||
);
|
||||
|
||||
router.get("/current_user", (req, res) => {
|
||||
auth.get("/current_user", (req, res) => {
|
||||
console.log("Current user endpoint hit");
|
||||
console.log("Request user:", req.user);
|
||||
if (req.isAuthenticated()) {
|
||||
|
|
@ -76,16 +76,16 @@ router.get("/current_user", (req, res) => {
|
|||
// }
|
||||
// });
|
||||
|
||||
router.get("/login/failed", (req, res) => {
|
||||
auth.get("/login/failed", (req, res) => {
|
||||
res.status(401).json({
|
||||
error: true,
|
||||
message: "Log in failure",
|
||||
});
|
||||
});
|
||||
|
||||
router.get("/google", passport.authenticate("google", ["profile", "email"]));
|
||||
auth.get("/google", passport.authenticate("google", ["profile", "email"]));
|
||||
|
||||
router.post(
|
||||
auth.post(
|
||||
"/student/login",
|
||||
passport.authenticate("student-auth", { keepSessionInfo: true }),
|
||||
(req, res) => {
|
||||
|
|
@ -117,7 +117,7 @@ router.post(
|
|||
}
|
||||
);
|
||||
|
||||
router.get("/logout", (req, res) => {
|
||||
auth.get("/logout", (req, res) => {
|
||||
req.logout((err) => {
|
||||
if (err) {
|
||||
return next(err);
|
||||
|
|
@ -126,4 +126,4 @@ router.get("/logout", (req, res) => {
|
|||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
module.exports = auth;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue