forked from fr/deguapp
		
	Added: fully working signin/signup system with routing
This commit is contained in:
		@@ -11,7 +11,7 @@ services:
 | 
			
		||||
    image: mongo-express
 | 
			
		||||
    restart: always
 | 
			
		||||
    ports:
 | 
			
		||||
      - 8081:8081
 | 
			
		||||
      - 8091:8081
 | 
			
		||||
    environment:
 | 
			
		||||
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
 | 
			
		||||
      ME_CONFIG_MONGODB_ADMINPASSWORD: root
 | 
			
		||||
 
 | 
			
		||||
@@ -23,6 +23,7 @@
 | 
			
		||||
		"bcrypt": "^5.1.1",
 | 
			
		||||
		"colors": "1.4.0",
 | 
			
		||||
		"cookie-parser": "^1.4.6",
 | 
			
		||||
		"cors": "^2.8.5",
 | 
			
		||||
		"dotenv": "^16.4.5",
 | 
			
		||||
		"express": "^4.19.2",
 | 
			
		||||
		"fs-extra": "^10.0.0",
 | 
			
		||||
@@ -41,6 +42,7 @@
 | 
			
		||||
		"@types/bcrypt": "^5.0.2",
 | 
			
		||||
		"@types/chai": "^4.2.22",
 | 
			
		||||
		"@types/cookie-parser": "^1.4.7",
 | 
			
		||||
		"@types/cors": "^2.8.17",
 | 
			
		||||
		"@types/express": "^4.17.21",
 | 
			
		||||
		"@types/fs-extra": "^9.0.13",
 | 
			
		||||
		"@types/inquirer": "^8.1.3",
 | 
			
		||||
 
 | 
			
		||||
@@ -1,29 +1,29 @@
 | 
			
		||||
import express from "express";
 | 
			
		||||
import morgan from "morgan";
 | 
			
		||||
import path from 'path'
 | 
			
		||||
//import cors from 'cors'
 | 
			
		||||
import cors from 'cors'
 | 
			
		||||
import cookieParser from 'cookie-parser'
 | 
			
		||||
import { router as routes } from "./routes";
 | 
			
		||||
//import { router as middlewares } from './middlewares'
 | 
			
		||||
//import env from './config/environment'
 | 
			
		||||
import env from './config/environment'
 | 
			
		||||
 | 
			
		||||
//export let corsWhitelist: Array<string>
 | 
			
		||||
//if (env.CORS_WHITELIST != 'undefined') {
 | 
			
		||||
//	corsWhitelist = [...['http://localhost:8080', 'http://localhost:6040'], ...env.CORS_WHITELIST.split(';')]
 | 
			
		||||
//} else {
 | 
			
		||||
//	corsWhitelist = ['http://localhost:8080', 'http://localhost:6040']
 | 
			
		||||
//}
 | 
			
		||||
//const corsOptions = {
 | 
			
		||||
//	origin: function (origin: any, callback: any) {
 | 
			
		||||
//		if (!origin || corsWhitelist.indexOf(origin) !== -1) {
 | 
			
		||||
//			callback(null, true)
 | 
			
		||||
//		} else {
 | 
			
		||||
//			callback(new Error('Not allowed by CORS'))
 | 
			
		||||
//		}
 | 
			
		||||
//	},
 | 
			
		||||
//	optionsSuccessStatus: 200,
 | 
			
		||||
//	credentials: true
 | 
			
		||||
//}
 | 
			
		||||
export let corsWhitelist: Array<string>
 | 
			
		||||
if (env.CORS_WHITELIST != 'undefined') {
 | 
			
		||||
	corsWhitelist = [...['http://localhost:8080', 'http://localhost:6040'], ...env.CORS_WHITELIST.split(';')]
 | 
			
		||||
} else {
 | 
			
		||||
	corsWhitelist = ['http://localhost:8080', 'http://localhost:6040']
 | 
			
		||||
}
 | 
			
		||||
const corsOptions = {
 | 
			
		||||
	origin: function (origin: any, callback: any) {
 | 
			
		||||
		if (!origin || corsWhitelist.indexOf(origin) !== -1) {
 | 
			
		||||
			callback(null, true)
 | 
			
		||||
		} else {
 | 
			
		||||
			callback(new Error('Not allowed by CORS'))
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
	optionsSuccessStatus: 200,
 | 
			
		||||
	credentials: true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const app = express();
 | 
			
		||||
 | 
			
		||||
@@ -31,7 +31,7 @@ export const app = express();
 | 
			
		||||
//app.use(middlewares)
 | 
			
		||||
//app.set('view engine', 'ejs')
 | 
			
		||||
//app.set('views', path.join(__dirname, 'views'))
 | 
			
		||||
//app.use(cors(corsOptions))
 | 
			
		||||
app.use(cors(corsOptions))
 | 
			
		||||
app.use(morgan("dev"));
 | 
			
		||||
app.use(express.urlencoded({ extended: true }));
 | 
			
		||||
app.use(express.json());
 | 
			
		||||
 
 | 
			
		||||
@@ -52,7 +52,7 @@ export async function signin_post(req: Request, res: Response) {
 | 
			
		||||
			res.cookie('jwt', token, { httpOnly: true, maxAge: maxAge * 1000 });
 | 
			
		||||
			res.cookie('auth', true, { httpOnly: false, maxAge: maxAge * 1000 });
 | 
			
		||||
 | 
			
		||||
			res.json(Log.info(200, 'user is logged in'));
 | 
			
		||||
			res.json(Log.info(200, 'user is logged in', {jwt: token}));
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,7 @@ router.get('/', docsController.docs_get);
 | 
			
		||||
 | 
			
		||||
router.post("/auth/signup",validate(AuthVal.signup) , authController.signup_post);
 | 
			
		||||
router.post("/auth/signin",validate(AuthVal.signin) , authController.signin_post);
 | 
			
		||||
router.options("/auth/signin",validate(AuthVal.signin) , authController.signin_post);
 | 
			
		||||
router.post("/auth/logout", requireAuth, authController.logout_post);
 | 
			
		||||
router.get("/auth/status", requireAuth, authController.status_get);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,5 +2,5 @@ import * as shell from 'shelljs';
 | 
			
		||||
 | 
			
		||||
// Copy all the view templates
 | 
			
		||||
//shell.cp('-R', 'src/views', 'dist/')
 | 
			
		||||
//shell.cp('-R', 'src/public', 'dist/');
 | 
			
		||||
shell.cp('-u', 'src/.env', 'dist/');
 | 
			
		||||
shell.cp('-R', 'src/public', 'dist/');
 | 
			
		||||
shell.cp('-u', 'src/.env', 'dist/');
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user