file index changed to class component

parent 40667cb7
MONGO_URL='mongodb://localhost:27017'
PORT='3000'
\ No newline at end of file
PORT='8002'
\ No newline at end of file
......@@ -6,19 +6,34 @@ import {UsersRouter} from './routes/user';
import { CommentController } from './controllers/comments';
import { PostsController } from './controllers/posts';
mongo.run();
const app: Express = express();
app.use(json());
app.use(cors());
app.use(urlencoded({extended: true}));
class App {
private app: Express
constructor() {
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'));
app.use('/users', UsersRouter);
app.use('/posts', new PostsController().getRouter())
app.use('/comments', new CommentController().getRouter())
app.use('/comments', new CommentController().getRouter())
public init = async (): Promise<void> => {
try {
await mongo.init()
process.on('exit', () => {
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, () => {
console.log(`App started on port ${process.env.PORT}`);
});
const app = new App()
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