Created
June 26, 2020 07:50
-
-
Save kianaditya/00128a82a04dc83a58062400523f5b71 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('dotenv').config() | |
const express = require('express') | |
const logger = require('morgan') | |
const db = require('./models') | |
const { createSeeds, deleteSeeds } = require('./models/seeders') | |
const app = express() | |
const PORT = process.env.PORT | |
app.use(logger('dev')) | |
app.use(express.json()) | |
app.use(express.urlencoded({ extended: false })) | |
const auth = require('./auth') | |
const postRouter = require('./routes/posts') | |
const passport = require('passport') | |
app.use(passport.initialize()); | |
app.use(passport.session()); | |
app.use(auth) | |
app.use('/posts', postRouter) | |
const seed = process.argv[2] | |
if (seed) { | |
db.sequelize | |
.sync({ force: true }) | |
.then(() => { | |
seed === 'create' ? createSeeds() : deleteSeeds() | |
}) | |
.catch((err) => { | |
console.error(err) | |
}) | |
} else { | |
db.sequelize | |
.sync() | |
.then(() => { | |
app.listen(PORT, () => { | |
console.info(`App listening on port ${PORT}`) | |
}) | |
}) | |
.catch((err) => { | |
console.error(err) | |
}) | |
} | |
module.exports = app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment