import bodyParser from 'body-parser' import express from 'express' import mongoose from 'mongoose' import AdminTagController from './controllers/AdminTagController' import DefaultController from './controllers/DefaultController' import MediaController from './controllers/MediaController' import dotenv from 'dotenv' console.log('WOOWOWO') dotenv.config({ path: __dirname + '/../.env' }) const app: express.Application = express() const host: string = "0.0.0.0" const port: number = 8001 let main = async () => { mongoose.connection.on('error', err => { console.error(err) }) mongoose.connect( process.env.MONGO_URI === undefined ? 'mongodb://root:root@localhost:27017/forumvirt' : process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true } ).then(() => { console.log('> Connected to mongodb') }) app.use(bodyParser.json()) app.get('/', DefaultController.home) app.get('/association/:slug', DefaultController.publicOrganization) app.get('/email', DefaultController.sendEmail) app.get('/api/tags', AdminTagController.getTags) app.put('/api/tags/:id', AdminTagController.updateTag) app.post('/api/tags', AdminTagController.storeTag) app.delete('/api/tags/:id', AdminTagController.destroyTag) app.post('/api/upload', MediaController.uploadRoute()) app.listen(port, host, () => { console.log(`API listening on ${host}:${port}`) }) } main()