-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.ts
63 lines (56 loc) · 1.76 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import {ApolloServerPluginLandingPageGraphQLPlayground} from 'apollo-server-core';
import {ApolloServer} from 'apollo-server-express';
import cors from 'cors';
import dotenv from 'dotenv';
import express from 'express';
import fileupload from 'express-fileupload';
import {env} from 'process';
import {buildSchema} from 'type-graphql';
import {createConnection} from 'typeorm';
import {MyContext} from './@types/types';
import db from './db.config';
import fileUpload from './isolated/s3/file.upload';
import tts from './isolated/tts/tts.route';
import {AnalyticsResolver} from './resolvers/analytics';
import {HelloResolver} from './resolvers/hello';
import {PostResolver} from './resolvers/post';
import {UserResolver} from './resolvers/user';
dotenv.config({path: './local.env'});
const app = express();
app.use(express.json());
const main = async () => {
// @ts-ignore
const conn = await createConnection(db);
app.use(
cors({
origin: env.CORS_ORIGIN,
credentials: true
})
);
app.use(fileupload());
app.get('/', (req, res) => {
res.send('Welcome to server baby');
});
app.use('/', fileUpload);
app.use('/', tts);
// -------------- Cookie setup end ----------------
const apolloServer = new ApolloServer({
plugins: [ApolloServerPluginLandingPageGraphQLPlayground()],
schema: await buildSchema({
resolvers: [HelloResolver, PostResolver, UserResolver, AnalyticsResolver],
validate: false
}),
context: ({req, res}): MyContext => ({req, res})
});
await apolloServer.start();
apolloServer.applyMiddleware({
app,
cors: true
});
const listener = app.listen(env.PORT || 4000);
// @ts-ignore
console.log(`Server listening on port ${listener.address().port}`);
};
main().catch(err => {
console.error(err);
});