Skip to content
Open

Task #210

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module.exports = {
extends: '@mate-academy/eslint-config',
ignorePatterns: ['src/frontend/**'],
env: {
jest: true
jest: true,
},
rules: {
'no-proto': 0
'no-proto': 0,
},
plugins: ['jest']
plugins: ['jest'],
};
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm --prefix src/frontend install
- run: npm test
24 changes: 24 additions & 0 deletions .github/workflows/test.yml-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Test

on:
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm --prefix src/frontend install
- run: npm test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# Node
node_modules

.env
.env.*
# MacOS
.DS_Store
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules
/dist
src/frontend/dist
35 changes: 19 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"description": "Chat using Node.js",
"main": "src/index.js",
"scripts": {
"backend": "npm --prefix src/backend start",
"init": "mate-scripts init",
"start": "node src/index.js",
"lint": "npm run format && mate-scripts lint",
"format": "prettier --ignore-path .prettierignore --write './src/**/*.{js,ts}'",
"start": "npm run backend",
"lint": "npm run format && mate-scripts lint --javascript ./src/backend ./src/index.js && npm --prefix src/frontend run lint",
"format": "prettier --ignore-path .prettierignore --write './src/**/*.{js,ts,tsx}'",
"test:only": "mate-scripts test",
"update": "mate-scripts update",
"postinstall": "npm run update",
Expand All @@ -17,7 +18,7 @@
"license": "GPL-3.0",
"devDependencies": {
"@mate-academy/eslint-config": "latest",
"@mate-academy/scripts": "^1.8.6",
"@mate-academy/scripts": "^2.1.3",
"eslint": "^8.57.0",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-node": "^11.1.0",
Expand Down
22 changes: 21 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Chat (with Node.js)
# Chat (with Node.js)
Implement a chat application (both client and server)

- You type a username and send it to the server
Expand All @@ -7,4 +7,24 @@ Implement a chat application (both client and server)
- Implement an ability to create rooms (create / rename / join / delete)
- New user should see all prev messages in the room

## Run locally

```bash
npm install
npm --prefix src/backend install
npm --prefix src/frontend install
```

Start the backend server:

```bash
npm run backend
```

Start the frontend:

```bash
npm --prefix src/frontend run dev
```

**Read [the guideline](https://github.com/mate-academy/js_task-guideline/blob/master/README.md) before start**
19 changes: 19 additions & 0 deletions src/backend/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

const express = require('express');
const authRoutes = require('./routes/authRoutes');
const errorHandler = require('./middleware/errorHandler');

function createApp() {
const app = express();

app.use(express.json());
app.use('/api', authRoutes);
app.use(errorHandler);

return app;
}

module.exports = {
createApp,
};
29 changes: 29 additions & 0 deletions src/backend/config/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* eslint-disable indent */
'use strict';

const path = require('path');
const fs = require('fs');

const envPath =
[
path.resolve(__dirname, '..', '.env'),
path.resolve(__dirname, '..', '..', 'server', '.env'),
path.resolve(__dirname, '..', '..', '..', 'server', '.env'),
].find((filePath) => fs.existsSync(filePath)) ||
path.resolve(__dirname, '..', '.env');

require('dotenv').config({
path: envPath,
quiet: true,
});

const databaseUrl =
process.env.DATABASE_URL || 'postgresql://localhost:5432/node_chat';

const shouldUseSsl =
databaseUrl.includes('sslmode=require') || databaseUrl.includes('neon.tech');

module.exports = {
databaseUrl,
shouldUseSsl,
};
Loading
Loading