Added: fully working signin/signup system with routing
This commit is contained in:
		@@ -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