Skip to content

Commit 0961e39

Browse files
authored
Merge branch 'master' into feature/implement-autoScroll
2 parents d6c23f6 + d8cc293 commit 0961e39

76 files changed

Lines changed: 932 additions & 890 deletions

Some content is hidden

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

‎.dockerignore‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.vscode
2+
dist
3+
node_modules
4+
.editorconfig
5+
.env
6+
.env.example
7+
.gitignore
8+
package-lock.json
9+
README.md

‎.github/workflows/cd.yml‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Continuos Deployment workflow
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
env:
9+
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
10+
11+
jobs:
12+
cd:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v2
17+
- name: Install heroku and login
18+
# Login using HEROKU_API_KEY env variable
19+
run: |
20+
curl https://cli-assets.heroku.com/install-ubuntu.sh | sh
21+
heroku container:login
22+
- name: Build docker image
23+
run: docker build --build-arg BASE_API_URL=${{ secrets.BASE_API_URL }} --build-arg BASE_SOCKET_URL=${{ secrets.BASE_SOCKET_URL }} -t registry.heroku.com/${{ secrets.HEROKU_APP_NAME }}/web .
24+
- name: Deploy docker image
25+
run: docker push registry.heroku.com/${{ secrets.HEROKU_APP_NAME }}/web
26+
- name: Release
27+
run: heroku container:release web -a ${{ secrets.HEROKU_APP_NAME }}

‎Dockerfile‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM node:12-alpine AS base
2+
RUN mkdir -p /usr/app
3+
WORKDIR /usr/app
4+
5+
# Build front
6+
FROM base AS build-frontend
7+
ARG BASE_API_URL
8+
ENV BASE_API_URL=$BASE_API_URL
9+
ARG BASE_SOCKET_URL
10+
ENV BASE_SOCKET_URL=$BASE_SOCKET_URL
11+
COPY ./front ./
12+
RUN npm install
13+
RUN npm run build
14+
15+
# Build backend
16+
FROM base AS build-backend
17+
COPY ./back ./
18+
RUN npm install
19+
RUN npm run build
20+
21+
# Release
22+
FROM base AS release
23+
COPY --from=build-backend /usr/app/dist ./
24+
COPY --from=build-frontend /usr/app/dist ./public
25+
COPY ./back/package.json ./
26+
RUN npm install --only=production
27+
28+
ENTRYPOINT [ "node", "index" ]

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<p align="center">
2323
Code Paster is a Teacher-to-Student communication tool for online programming lessons. Create a new session and easily share your code with all students connected so they can follow along with your examples.
2424
</p>
25+
<p>
26+
Click here to navigate to <a href="https://www.codepaster.net/">Codepaster</a>
27+
</p>
2528
</p>
2629
<br />
2730

‎back/.babelrc‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
"core": "./src/core",
2323
"dals": "./src/dals",
2424
"pods": "./src/pods",
25-
"messages": "./src/messages",
26-
"business": "./src/business"
2725
}
2826
}
2927
]

‎back/.env‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
NODE_ENV=development
22
PORT=8081
3-
SOCKET_PORT=3000
43
MOCK_REPOSITORY=false
54
API_URL=/api
65
CORS_ORIGIN=http://localhost:8080
76
MONGODB_URI=mongodb://localhost:27017/code-paster
7+
STATIC_FILES_PATH="../../front/dist"
8+
MONGO_EXPIRATION_TIME='2d'

‎back/.vscode/launch.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"runtimeExecutable": null,
1111
"runtimeArgs": ["--nolazy"],
1212
"env": {
13-
"NODE_ENV": "development"
13+
"NODE_ENV": "development",
14+
"MOCK_REPOSITORY": "true"
1415
},
1516
"console": "internalConsole",
1617
"sourceMaps": true,

‎back/src/app.ts‎

Lines changed: 11 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,24 @@
1-
import cors from 'cors';
2-
import SocketIOClient, { Socket } from 'socket.io';
1+
import express from 'express';
2+
import path from 'path';
33

4-
import { createApp } from './express.server';
5-
import { envConstants, connectToDB } from 'core';
6-
import { api } from './api';
7-
import { processInputMessage, InputMessageTypes, processOutputMessageCollection, Action, SocketInfo } from './messages';
4+
import { createApp, createSocketServer } from 'core/servers';
5+
import { connectToDB } from 'core/db';
6+
import { envConstants } from 'core/constants';
7+
import { api } from 'pods/room';
88

99
const app = createApp();
10-
11-
let http = require('http').Server(app);
12-
// set up socket.io and bind it to our
13-
// http server.
14-
let io: SocketIOClient.Socket = require('socket.io')(http);
15-
16-
//options for cors midddleware
17-
const options: cors.CorsOptions = {
18-
allowedHeaders: [
19-
'Origin',
20-
'X-Requested-With',
21-
'Content-Type',
22-
'Accept',
23-
'X-Access-Token',
24-
],
25-
credentials: true,
26-
methods: 'GET,HEAD,OPTIONS,PUT,PATCH,POST,DELETE',
27-
// IMPORTANT LIMIT HERE YOUR CLIENT APPS DOMAINS
28-
origin: '*',
29-
preflightContinue: false,
30-
};
31-
32-
app.use(cors(options));
3310
app.use(envConstants.API_URL, api);
3411

35-
app.listen(envConstants.PORT, async () => {
12+
const staticFilesPath = path.resolve(__dirname, envConstants.STATIC_FILES_PATH);
13+
app.use('/', express.static(staticFilesPath));
14+
15+
const appServer = app.listen(envConstants.PORT, async () => {
3616
if(!envConstants.isMockRepository && envConstants.MONGODB_URI) {
3717
await connectToDB(envConstants.MONGODB_URI);
3818
}
3919
console.log(`Using ${envConstants.isMockRepository ? 'Mock' : 'DataBase'} for session storage`)
4020
console.log(`Server ready at http://localhost:${envConstants.PORT}${envConstants.API_URL}`);
4121
});
4222

43-
// whenever a user connects on port 3000 via
44-
// a websocket, log that a user has connected
45-
io.on('connection', async function (socket: Socket) {
46-
// WATCH OUT !! Reconnect is not implemented
47-
// In the connection input processing, we should
48-
// check if connectionId matches with userId and RoomId
49-
// if not reject, if it's accepted send connection
50-
// reestablished
51-
const { room, trainertoken } = socket.handshake.query;
52-
console.log(`room request: ${room}`);
53-
console.log(`trainer token: ${trainertoken}`);
54-
console.log('*** Session ID:', socket.conn.id);
55-
56-
let outputMessageCollection: Action[] = [];
57-
const socketInfo: SocketInfo = {
58-
socket: socket,
59-
io,
60-
connectionId: socket.conn.id,
61-
};
62-
63-
// TODO encapuslate this to processInputMessage
64-
if (trainertoken) {
65-
outputMessageCollection = await processInputMessage(socketInfo, {
66-
type: InputMessageTypes.ESTABLISH_CONNECTION_TRAINER,
67-
payload: {
68-
room,
69-
trainertoken,
70-
},
71-
});
72-
} else {
73-
outputMessageCollection = await processInputMessage(socketInfo, {
74-
type: InputMessageTypes.ESTABLISH_CONNECTION_STUDENT,
75-
payload: {
76-
room,
77-
},
78-
});
79-
}
80-
81-
processOutputMessageCollection(socketInfo, outputMessageCollection);
82-
83-
socket.on('message', async function (message: any) {
84-
console.log(message);
85-
if (message && message.type) {
86-
const outputMessageCollection: Action[] = await processInputMessage(
87-
socketInfo,
88-
message
89-
);
23+
createSocketServer(appServer);
9024

91-
await processOutputMessageCollection(socketInfo, outputMessageCollection);
92-
}
93-
});
94-
});
95-
96-
const server = http.listen(3001, function () {
97-
console.log('listening on *:3001');
98-
});

‎back/src/business/index.ts‎

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
export const envConstants = {
2-
NODE_ENV: process.env.NODE_ENV,
3-
PORT: process.env.PORT,
4-
SOCKET_PORT: process.env.SOCKET_PORT,
5-
isMockRepository: process.env.MOCK_REPOSITORY === 'true',
6-
MONGODB_URI: process.env.MONGODB_URI,
7-
API_URL: process.env.API_URL,
8-
CORS_ORIGIN: process.env.CORS_ORIGIN,
9-
};
10-
2+
NODE_ENV: process.env.NODE_ENV,
3+
PORT: process.env.PORT,
4+
isMockRepository: process.env.MOCK_REPOSITORY === 'true',
5+
MONGODB_URI: process.env.MONGODB_URI,
6+
API_URL: process.env.API_URL,
7+
CORS_ORIGIN: process.env.CORS_ORIGIN,
8+
isProduction: process.env.NODE_ENV === 'production',
9+
STATIC_FILES_PATH: process.env.STATIC_FILES_PATH,
10+
MONGO_EXPIRATION_TIME: process.env.MONGO_EXPIRATION_TIME,
11+
};

0 commit comments

Comments
 (0)