Skip to content

Commit 8bd1631

Browse files
committed
Co-authored-by: seantokuzo <[email protected]>
2 parents cc2c09b + 0f5e233 commit 8bd1631

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+10999
-52
lines changed

examples_new/microservices/auth/package-lock.json

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples_new/microservices/auth/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"axios": "^1.6.2",
2323
"bcryptjs": "^2.4.3",
2424
"cookie-parser": "^1.4.6",
25+
"cors": "^2.8.5",
2526
"dotenv": "^16.3.1",
2627
"express": "^4.18.2",
2728
"express-async-errors": "^3.1.1",
@@ -32,6 +33,7 @@
3233
"devDependencies": {
3334
"@types/bcryptjs": "^2.4.6",
3435
"@types/cookie-parser": "^1.4.6",
36+
"@types/cors": "^2.8.17",
3537
"@types/express": "^4.17.21",
3638
"@types/jest": "^29.5.11",
3739
"@types/jsonwebtoken": "^9.0.5",

examples_new/microservices/auth/src/app.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ import { NotFoundError, errorHandler } from '@chronosrx/common';
66
import authRouter from './routes/auth-router';
77
import eventRouter from './routes/event-router';
88
import cookieParser from 'cookie-parser';
9+
import cors from 'cors';
910

1011
const app = express();
1112

13+
app.use(
14+
cors({
15+
credentials: true,
16+
origin: 'http://localhost:8080',
17+
})
18+
);
1219
app.use(express.json());
1320
app.use(cookieParser());
1421

examples_new/microservices/auth/src/controllers/auth-controller.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Request, Response } from 'express';
2-
import axios from 'axios';
2+
import axios, { AxiosError } from 'axios';
33
import { BadRequestError, CurrentUserRequest, Events } from '@chronosrx/common';
44
import { User } from '../models/user';
55
import { attachCookie } from '../util/attachCookie';
@@ -29,12 +29,20 @@ export const signup = async (req: Request, res: Response) => {
2929

3030
// TODO PUBLISH AN EVENT TO THE EVENT BUS - type USER_CREATED, with data of user - user.id & username
3131
// console.log('Publishing event USER_CREATED');
32-
await axios.post('http://localhost:3005/', {
33-
event: {
34-
type: Events.USER_CREATED,
35-
payload: newUser,
36-
},
37-
});
32+
try {
33+
await axios.post('http://localhost:3005/', {
34+
event: {
35+
type: Events.USER_CREATED,
36+
payload: newUser,
37+
},
38+
});
39+
} catch (err) {
40+
console.log(
41+
`Failed to emit event USER_CREATED from auth: ${
42+
(err as AxiosError).message || 'unknown error'
43+
} `
44+
);
45+
}
3846

3947
// create a JWT w/ userId store on it
4048
// note: createJwt method created on the userSchema
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
root: true,
3+
env: { browser: true, es2020: true },
4+
extends: [
5+
'eslint:recommended',
6+
'plugin:@typescript-eslint/recommended',
7+
'plugin:react-hooks/recommended',
8+
],
9+
ignorePatterns: ['dist', '.eslintrc.cjs'],
10+
parser: '@typescript-eslint/parser',
11+
plugins: ['react-refresh'],
12+
rules: {
13+
'react-refresh/only-export-components': [
14+
'warn',
15+
{ allowConstantExport: true },
16+
],
17+
},
18+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# React + TypeScript + Vite
2+
3+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4+
5+
Currently, two official plugins are available:
6+
7+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9+
10+
## Expanding the ESLint configuration
11+
12+
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
13+
14+
- Configure the top-level `parserOptions` property like this:
15+
16+
```js
17+
export default {
18+
// other rules...
19+
parserOptions: {
20+
ecmaVersion: 'latest',
21+
sourceType: 'module',
22+
project: ['./tsconfig.json', './tsconfig.node.json'],
23+
tsconfigRootDir: __dirname,
24+
},
25+
}
26+
```
27+
28+
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
29+
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
30+
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<link rel="preconnect" href="https://fonts.googleapis.com" />
8+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
9+
<link
10+
href="https://fonts.googleapis.com/css2?family=Concert+One&family=Kdam+Thmor+Pro&family=Rubik:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,300&display=swap"
11+
rel="stylesheet"
12+
/>
13+
<title>Chronos Microservices</title>
14+
</head>
15+
<body>
16+
<div id="root"></div>
17+
<script type="module" src="/src/main.tsx"></script>
18+
</body>
19+
</html>

0 commit comments

Comments
 (0)