file index changed to class component

parent 40667cb7
MONGO_URL='mongodb://localhost:27017' MONGO_URL='mongodb://localhost:27017'
PORT='3000' PORT='8002'
\ No newline at end of file \ No newline at end of file
...@@ -6,19 +6,34 @@ import {UsersRouter} from './routes/user'; ...@@ -6,19 +6,34 @@ import {UsersRouter} from './routes/user';
import { CommentController } from './controllers/comments'; import { CommentController } from './controllers/comments';
import { PostsController } from './controllers/posts'; import { PostsController } from './controllers/posts';
mongo.run();
const app: Express = express(); class App {
app.use(json()); private app: Express
app.use(cors()); constructor() {
app.use(urlencoded({extended: true})); this.app = express()
this.app.use(express.json())
this.app.use(express.static('public'))
this.app.use(express.urlencoded({extended: true}));
this.app.use(cors())
}
app.use(express.static('public/uploads')); public init = async (): Promise<void> => {
app.use('/users', UsersRouter); try {
app.use('/posts', new PostsController().getRouter()) await mongo.init()
app.use('/comments', new CommentController().getRouter()) process.on('exit', () => {
app.use('/comments', new CommentController().getRouter()) mongo.close()
})
this.app.use('/posts', new PostsController().getRouter())
this.app.use('/users', UsersRouter)
this.app.use('/comments', new CommentController().getRouter())
this.app.listen(process.env.PORT, () => {
console.log(`Server is running on port ${process.env.PORT}`)
})
} catch(err: unknown) {
console.log(err)
}
}
}
app.listen(process.env.PORT, () => { const app = new App()
console.log(`App started on port ${process.env.PORT}`); app.init()
}); \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment