-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (36 loc) · 858 Bytes
/
index.js
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
const express = require('express')
const path = require('path')
const sequelize = require('./utils/database')
const { graphqlHTTP } = require("express-graphql");
const schema = require('./graphql/schema')
const resolver = require('./graphql/resolver')
const app = express()
const PORT = process.env.PORT || 3000
// set static response
app.use(express.static(path.join(__dirname, 'public')))
// set parse json
app.use(express.json())
// set graphQL
app.use(
graphqlHTTP({
schema: schema,
rootValue: resolver,
graphiql: true
})
);
// send .html response
app.use((req, res, next) => {
res.sendFile('/index.html')
})
async function start() {
try {
// connect to db
await sequelize.sync()
app.listen(PORT, () => {
console.log(`app run on PORT ${PORT}`)
})
} catch (e) {
console.log(e)
}
}
start()