server/src/app.ts

53 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-06-27 21:23:09 +00:00
import bodyParser from 'body-parser'
2020-06-27 21:23:09 +00:00
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'
})
2020-06-27 21:23:09 +00:00
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)
})
2020-06-27 21:23:09 +00:00
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}`)
})
}
2020-06-27 21:23:09 +00:00
main()