Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat][ci] implement linting using GitHub actions #70

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
42 changes: 42 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module.exports = {
env: {
es2021: true,
node: true,
},
extends: [
"eslint:recommended",
"plugin:react/recommended",
],
settings: {
react: {
version: "18.2",
},
},
overrides: [
],
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
plugins: [
"react",
],
rules: {
indent: [
"error",
2,
],
"linebreak-style": [
"error",
"unix",
],
quotes: [
"error",
"double",
],
semi: [
"error",
"always",
],
},
};
22 changes: 22 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: lint

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node and cache dependencies
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'npm'
- name: install dependencies
run: npm install
- name: Lint files
run: npm run lint
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*/node_modules
node_modules
*/.env
*.sqlite
.vscode
2 changes: 0 additions & 2 deletions .vscode/settings.json

This file was deleted.

30 changes: 15 additions & 15 deletions api-gateway/index.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import express from 'express';
import cors from 'cors';
import morgan from 'morgan';
import cookieParser from 'cookie-parser';
import 'dotenv/config';
import express from "express";
import cors from "cors";
import morgan from "morgan";
import cookieParser from "cookie-parser";
import "dotenv/config";
import {
userProxy,
matchingProxy,
codingProxy,
videoProxy,
questionProxy,
historyProxy,
} from './proxy.js';
} from "./proxy.js";

const app = express();
app.use(
cors({
//replace with deployed endpoint
origin: 'http://localhost:3000',
// replace with deployed endpoint
origin: "http://localhost:3000",
credentials: true,
})
}),
); // config cors so that front-end can use
app.use(cookieParser());
app.use(morgan('combined'));
app.use(morgan("combined"));

app.use('/user', userProxy);
app.use("/user", userProxy);
app.use(matchingProxy);
app.use(codingProxy);
app.use('/video', videoProxy);
app.use('/question', questionProxy);
app.use('/history', historyProxy);
app.use("/video", videoProxy);
app.use("/question", questionProxy);
app.use("/history", historyProxy);

const server = app.listen(8080, () => {
console.log('api gateway running on port 8080');
console.log("api gateway running on port 8080");
});
8 changes: 4 additions & 4 deletions api-gateway/middleware/auth.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import axios from 'axios';
import axios from "axios";

export const authenticate = async (req, res, next) => {
const { token } = req.cookies;
await axios
.get('http://localhost:8000/auth', {
.get("http://localhost:8000/auth", {
headers: {
Cookie: `token=${token}`,
},
})
.then((resp) => {
if (resp.status != 200) {
res.status(401).json({ message: 'Invalid JWT token' });
res.status(401).json({ message: "Invalid JWT token" });
}
next();
})
.catch(() => res.status(401).json({ message: 'Missing JWT token' }));
.catch(() => res.status(401).json({ message: "Missing JWT token" }));
};

export default authenticate;
6 changes: 3 additions & 3 deletions api-gateway/proxy.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { createProxyMiddleware } from 'http-proxy-middleware';
import { createProxyMiddleware } from "http-proxy-middleware";

export const userProxy = createProxyMiddleware({
target: process.env.USER_URL,
changeOrigin: true,
});

export const matchingProxy = createProxyMiddleware('/matching', {
export const matchingProxy = createProxyMiddleware("/matching", {
target: process.env.MATCHING_URL,
changeOrigin: true,
ws: true,
});

export const codingProxy = createProxyMiddleware('/coding', {
export const codingProxy = createProxyMiddleware("/coding", {
target: process.env.CODING_URL,
changeOrigin: true,
ws: true,
Expand Down
30 changes: 15 additions & 15 deletions coding-service/index.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import express from 'express';
import cors from 'cors';
import http from 'http';
import { Server } from 'socket.io';
import express from "express";
import cors from "cors";
import http from "http";
import { Server } from "socket.io";

const app = express();
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cors()); // config cors so that front-end can use
app.options('*', cors());
app.options("*", cors());

const server = http.createServer(app);
const io = new Server(server, {
cors: {
origin: '*',
origin: "*",
},
path: '/coding',
path: "/coding",
});

var PORT = process.env.PORT || 8002;
const PORT = process.env.PORT || 8002;

app.get('/coding', (req, res) => {
res.send('Hello World from coding-service');
app.get("/coding", (req, res) => {
res.send("Hello World from coding-service");
});

io.on('connection', (socket) => {
console.log('a user connected to coding-service');
io.on("connection", (socket) => {
console.log("a user connected to coding-service");

socket.on('connectedToRoom', (roomId) => {
socket.on("connectedToRoom", (roomId) => {
const roomName = `ROOM:${roomId}`;
socket.join(roomName);
});

socket.on('codeChanged', (args) => {
socket.on("codeChanged", (args) => {
const { value, roomId } = args;
const roomName = `ROOM:${roomId}`;
socket.in(roomName).emit('codeChanged', value);
socket.in(roomName).emit("codeChanged", value);
});
});

Expand Down
6 changes: 0 additions & 6 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@
"test": "react-scripts test",
"lint": "npx eslint ."
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
Expand Down
Loading