Fixed ports
This commit is contained in:
@@ -1,25 +1,21 @@
|
|||||||
# Jira clone API built with Node/TypeScript
|
# Project structure
|
||||||
|
|
||||||
The API codebase is fairly simple and should be easy enough to understand.
|
The API codebase is fairly simple and should be easy enough to understand.
|
||||||
|
|
||||||
### Project structure
|
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
<!-- prettier-ignore-start -->
|
| File or folder | Description |
|
||||||
| File or folder | Description |
|
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| `src/index.ts` | The entry file. This is where we setup middleware, attach routes, initialize database and express. |
|
||||||
| `src/index.ts` | The entry file. This is where we setup middleware, attach routes, initialize database and express. |
|
| `src/routes.ts` | This is where we define all routes, both public and private. |
|
||||||
| `src/routes.ts` | This is where we define all routes, both public and private. |
|
| `src/constants` | Constants are values that never change and are used in multiple places across the codebase. |
|
||||||
| `src/constants` | Constants are values that never change and are used in multiple places across the codebase. |
|
| `src/controllers` | Controllers listen to client's requests and work with entities and the database to fetch, add, update, or delete data. |
|
||||||
| `src/controllers` | Controllers listen to client's requests and work with entities and the database to fetch, add, update, or delete data. |
|
| `src/database` | Database related code and seeds go here. |
|
||||||
| `src/database` | Database related code and seeds go here. |
|
| `src/entities` | This is where we put TypeORM entities, you could think of them as models. We define columns, relations, validations for each database entity. |
|
||||||
| `src/entities` | This is where we put TypeORM entities, you could think of them as models. We define columns, relations, validations for each database entity. |
|
| `src/errors` | This is where we define custom errors. The `catchErrors` function helps us avoid repetitive `try/catch` blocks within controllers. |
|
||||||
| `src/errors` | This is where we define custom errors. The `catchErrors` function helps us avoid repetitive `try/catch` blocks within controllers. |
|
| `src/middleware` | Middleware functions can modify request and response objects, end the request-response cycle, etc. For example `authenticateUser` method verifies the authorization token and attaches `currentUser` to the request object. |
|
||||||
| `src/middleware` | Middleware functions can modify request and response objects, end the request-response cycle, etc. For example `authenticateUser` method verifies the authorization token and attaches `currentUser` to the request object. |
|
| `src/serializers` | Serializers transform the data fetched from the database before it's sent to the client. |
|
||||||
| `src/serializers` | Serializers transform the data fetched from the database before it's sent to the client. |
|
| `src/utils` | Utility(helper) functions that are used in multiple places across the codebase. For example `utils/typeorm.ts` functions help us validate data and avoid writing repetitive code. |
|
||||||
| `src/utils` | Utility(helper) functions that are used in multiple places across the codebase. For example `utils/typeorm.ts` functions help us validate data and avoid writing repetitive code. |
|
|
||||||
<!-- prettier-ignore-end -->
|
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ const establishDatabaseConnection = async (): Promise<void> => {
|
|||||||
|
|
||||||
const initializeExpress = (): void => {
|
const initializeExpress = (): void => {
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = 3000;
|
|
||||||
|
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
@@ -39,7 +38,7 @@ const initializeExpress = (): void => {
|
|||||||
app.use((req, _res, next) => next(new RouteNotFoundError(req.originalUrl)));
|
app.use((req, _res, next) => next(new RouteNotFoundError(req.originalUrl)));
|
||||||
app.use(handleError);
|
app.use(handleError);
|
||||||
|
|
||||||
app.listen(PORT, () => console.log(`App listening on port ${PORT}`));
|
app.listen(process.env.PORT || 3000);
|
||||||
};
|
};
|
||||||
|
|
||||||
const initializeApp = async (): Promise<void> => {
|
const initializeApp = async (): Promise<void> => {
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ const express = require('express');
|
|||||||
const fallback = require('express-history-api-fallback');
|
const fallback = require('express-history-api-fallback');
|
||||||
const compression = require('compression');
|
const compression = require('compression');
|
||||||
|
|
||||||
const PORT = process.env.$PORT || process.env.PORT || 8080;
|
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.use(compression());
|
app.use(compression());
|
||||||
@@ -12,4 +10,4 @@ app.use(express.static(`${__dirname}/build`));
|
|||||||
|
|
||||||
app.use(fallback(`${__dirname}/build/index.html`));
|
app.use(fallback(`${__dirname}/build/index.html`));
|
||||||
|
|
||||||
app.listen(PORT);
|
app.listen(process.env.PORT || 8080);
|
||||||
|
|||||||
@@ -23,10 +23,12 @@ const useQuery = (url, propsVariables = {}, options = {}) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const makeRequest = useCallback(
|
const makeRequest = useCallback(
|
||||||
(newVariables, { skipLoading } = {}) => {
|
newVariables => {
|
||||||
const variables = { ...state.variables, ...(newVariables || {}) };
|
const variables = { ...state.variables, ...(newVariables || {}) };
|
||||||
const apiVariables = { ...propsVariablesMemoized, ...variables };
|
const apiVariables = { ...propsVariablesMemoized, ...variables };
|
||||||
|
|
||||||
|
const skipLoading = canUseCache && cachePolicy === 'cache-first';
|
||||||
|
|
||||||
if (!skipLoading) {
|
if (!skipLoading) {
|
||||||
mergeState({ isLoading: true, variables });
|
mergeState({ isLoading: true, variables });
|
||||||
} else if (newVariables) {
|
} else if (newVariables) {
|
||||||
@@ -53,20 +55,16 @@ const useQuery = (url, propsVariables = {}, options = {}) => {
|
|||||||
if (isSleeping) return;
|
if (isSleeping) return;
|
||||||
if (canUseCache && cachePolicy === 'cache-only') return;
|
if (canUseCache && cachePolicy === 'cache-only') return;
|
||||||
|
|
||||||
makeRequest(
|
makeRequest();
|
||||||
{},
|
|
||||||
{
|
|
||||||
skipLoading: canUseCache && cachePolicy === 'cache-first',
|
|
||||||
},
|
|
||||||
);
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [makeRequest]);
|
}, [makeRequest]);
|
||||||
|
|
||||||
const setLocalData = useCallback(
|
const setLocalData = useCallback(
|
||||||
getUpdatedData =>
|
getUpdatedData =>
|
||||||
mergeState(({ data }) => {
|
mergeState(({ data }) => {
|
||||||
cache[url] = { ...(cache[url] || {}), data: getUpdatedData(data) };
|
const updatedData = getUpdatedData(data);
|
||||||
return { data: getUpdatedData(data) };
|
cache[url] = { ...(cache[url] || {}), data: updatedData };
|
||||||
|
return { data: updatedData };
|
||||||
}),
|
}),
|
||||||
[mergeState, url],
|
[mergeState, url],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { objectToQueryString } from 'shared/utils/url';
|
|||||||
import { getStoredAuthToken, removeStoredAuthToken } from 'shared/utils/authToken';
|
import { getStoredAuthToken, removeStoredAuthToken } from 'shared/utils/authToken';
|
||||||
|
|
||||||
const defaults = {
|
const defaults = {
|
||||||
baseURL: 'http://localhost:3000',
|
baseURL: `http://localhost:${process.env.PORT || 3000}`,
|
||||||
headers: () => ({
|
headers: () => ({
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
Authorization: getStoredAuthToken() ? `Bearer ${getStoredAuthToken()}` : undefined,
|
Authorization: getStoredAuthToken() ? `Bearer ${getStoredAuthToken()}` : undefined,
|
||||||
|
|||||||
Reference in New Issue
Block a user