app access for dev
This commit is contained in:
parent
77236142d9
commit
071fb891d3
@ -51,6 +51,7 @@
|
||||
"@types/cors": "^2.8.7",
|
||||
"@types/express": "^4.17.7",
|
||||
"@types/faker": "^5.1.0",
|
||||
"@types/ip": "^1.1.0",
|
||||
"@types/lodash": "^4.14.159",
|
||||
"@types/morgan": "^1.9.1",
|
||||
"@types/node": "^14.6.0",
|
||||
@ -61,6 +62,7 @@
|
||||
"dotenv": "^8.2.0",
|
||||
"faker": "^5.1.0",
|
||||
"http-proxy-middleware": "^1.0.5",
|
||||
"ip": "^1.1.5",
|
||||
"rimraf": "^3.0.2",
|
||||
"webpack-node-externals": "^2.5.1"
|
||||
},
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { address } from 'ip';
|
||||
export const API_PORT = 3001;
|
||||
export const API_URL = "http://localhost:" + API_PORT;
|
||||
export const API_URL = `http://${address()}:${API_PORT}`;
|
||||
|
||||
export const CLIENT_DEV_URL = "http://localhost:3000";
|
||||
export const CLIENT_DEV_URL = 'http://localhost:3000';
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
import bodyParser from "body-parser";
|
||||
import compression from "compression";
|
||||
import cors from "cors";
|
||||
import bodyParser from 'body-parser';
|
||||
import compression from 'compression';
|
||||
import cors from 'cors';
|
||||
// import cookieParser from "cookie-parser";
|
||||
import express from "express";
|
||||
import express from 'express';
|
||||
// import nodeSSPI from "express-node-sspi";
|
||||
import helmet from "helmet";
|
||||
import morgan from "morgan";
|
||||
import path from "path";
|
||||
import "reflect-metadata";
|
||||
import routes from "./routes";
|
||||
import { CLIENT_DEV_URL, API_PORT } from "../core/constants/urls";
|
||||
import helmet from 'helmet';
|
||||
import morgan from 'morgan';
|
||||
import path from 'path';
|
||||
import 'reflect-metadata';
|
||||
import routes from './routes';
|
||||
import { CLIENT_DEV_URL, API_PORT } from '../core/constants/urls';
|
||||
|
||||
const isDevelopmentMode = process.env.NODE_ENV === "development";
|
||||
const isDevelopmentMode = process.env.NODE_ENV === 'development';
|
||||
|
||||
const buildDir = path.join(
|
||||
process.cwd(),
|
||||
process.env.NODE_ENV === "development" ? "/build" : ""
|
||||
process.env.NODE_ENV === 'development' ? '/build' : '',
|
||||
);
|
||||
|
||||
const app = express();
|
||||
@ -37,30 +37,31 @@ app.use(bodyParser.json());
|
||||
app.use(
|
||||
bodyParser.urlencoded({
|
||||
extended: true,
|
||||
})
|
||||
}),
|
||||
);
|
||||
app.use(helmet({ contentSecurityPolicy: { reportOnly: true } }));
|
||||
|
||||
if (isDevelopmentMode) {
|
||||
app.use(cors({ origin: CLIENT_DEV_URL, credentials: true }));
|
||||
}
|
||||
app.use(
|
||||
cors({ origin: isDevelopmentMode ? '*' : CLIENT_DEV_URL, credentials: true }),
|
||||
);
|
||||
|
||||
// app.use(cookieParser());
|
||||
app.use(compression());
|
||||
app.use(morgan("tiny"));
|
||||
app.use(morgan(isDevelopmentMode ? 'dev' : 'tiny'));
|
||||
/**EXTENTIONS */
|
||||
|
||||
/**ROUTES */
|
||||
app.use("/", routes);
|
||||
app.use('/', routes);
|
||||
/**ROUTES */
|
||||
|
||||
/**CLIENT */
|
||||
app.use(express.static(buildDir));
|
||||
app.get("*", function (req, res) {
|
||||
res.sendFile(path.join(buildDir, "index.html"));
|
||||
app.get('*', function (req, res) {
|
||||
res.sendFile(path.join(buildDir, 'index.html'));
|
||||
});
|
||||
/**CLIENT */
|
||||
|
||||
console.log("checking port", API_PORT);
|
||||
console.log('checking port', API_PORT);
|
||||
app.listen(API_PORT, () => {
|
||||
console.log(`Server now listening on port: ${API_PORT}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user