Skip to content
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
5 changes: 5 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
"@babel/preset-env"
]
}
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules

# testing

# production
/build

# misc
.env
.env.local
.env.test.local
.env.production.local
/docs/*.js
npm-debug.log*
yarn-debug.log*
yarn-error.log*
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": true,
"tabWidth": 2,
"printWidth": 100,
"singleQuote": true,
"trailingComma": "all",
"arrowParens": "avoid"
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"folders": [],
"settings": {},
"[javascript]": {
"editor.formatOnSave": true
}
}
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# JobChat-Training

## Infor:
- Nguyễn Văn A
- Demo: 01/01/2020
- Phạm Bùi Minh Trí
- Demo: 09/12/2019 - 13/12/2019

## Requirement:
- Authencation (login/register by email)
Expand All @@ -13,8 +13,6 @@
- View TO/REP

## Technical Require:
- Android: Kotlin, RxJava, RxAndroid, Firebase(Authencation, Realtime DB), MVP
- IOS: Swift, RxSwift, RxCocoa, Firebase(Authencation, Realtime DB) , MVP
- Web (NodeJS - VueJS/ReactJS): *TBD*

## Prototype:
Expand Down
96 changes: 96 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { createServer } from 'http';
import express from 'express';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import passport from 'passport';
import expressSession from 'express-session';
import redis from 'redis';
import { ApolloServer, PubSub } from 'apollo-server-express';
import typeDefs from './src/api/graphql/schemas';
import resolvers from './src/api/graphql/resolvers';
const pubsub = new PubSub();
import UserRepo from './src/api/graphql/datasources/UserRepo';
import MessageRepo from './src/api/graphql/datasources/MessageRepo';
import GroupChatRepo from './src/api/graphql/datasources/GroupChatRepo';
import RelationshipRepo from './src/api/graphql/datasources/RelationshipRepo';
import { secretSession, server, redisServer, origin_cors } from './src/config';
const cors = require('cors');
const redisStore = require('connect-redis')(expressSession);
const client = redis.createClient();
const app = express();
const port = server.port;

app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(cookieParser());
app.use(cors({ credentials: true, origin: origin_cors }));
app.use(
expressSession({
secret: secretSession,
store: new redisStore({
host: redisServer.host,
port: redisServer.host,
client: client,
ttl: redisServer.ttl,
}),
resave: false,
cookie: { secure: false, maxAge: 86400000 },
saveUninitialized: true,
}),
);

app.use(passport.initialize());
app.use(passport.session());

passport.serializeUser(function(user, done) {
done(null, user);
});

passport.deserializeUser(function(user, done) {
done(null, user);
});

require('./src/utils/authenGrantPassport');

app.post('/login', function(req, res, next) {
passport.authenticate('local', { session: true }, function(err, user, info) {
if (err) return next(err);
req.logIn(user, function(err) {
if (err) return next(err);
return res.json(user);
});
})(req, res, next);
});

const serverGraphql = new ApolloServer({
introspection: true,
typeDefs,
resolvers,
subscriptions: {
onConnect: () => console.log('Connected to websocket'),
formatError: error => {
return error;
},
},
context: async ({ req, res, connection }) => {
if (connection) return { connection, pubsub };
return {
req,
pubsub,
user: new UserRepo(),
message: new MessageRepo(),
groupChat: new GroupChatRepo(),
relationship: new RelationshipRepo(),
};
},
});

serverGraphql.applyMiddleware({ app, path: '/graphql' });

const httpServer = createServer(app);
serverGraphql.installSubscriptionHandlers(httpServer);

httpServer.listen(port, () => {
require('./src/database/db');
console.log(`app is listening to port ${port}`);
});
Loading