api copied to hudozka-api module based on express
This commit is contained in:
1 parent
70007d3199
commit
fc0724a900
21 files changed
+1093
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import dotenv from 'dotenv'
|
||||
import express from 'express'
|
||||
import { connect } from './db'
|
||||
import * as person from './controllers/person'
|
||||
import * as article from './controllers/article'
|
||||
import * as album from './controllers/album'
|
||||
import * as schedule from './controllers/schedule'
|
||||
import * as file from './controllers/file'
|
||||
import * as page from './controllers/page'
|
||||
import * as image from './controllers/image'
|
||||
|
||||
dotenv.config()
|
||||
|
||||
async function main() {
|
||||
const port = parseInt(process.env.PORT, 10) || 3000
|
||||
const mongoUri = process.env.MONGO_URI
|
||||
|
||||
try {
|
||||
await connect('hudozka', mongoUri)
|
||||
|
||||
console.log('connected')
|
||||
} catch (e) {
|
||||
console.error(e.message)
|
||||
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const app = express()
|
||||
app.get('/persons', person.getAll)
|
||||
app.get('/persons/urls', person.getUrls)
|
||||
app.get('/persons/:slug', person.getItem)
|
||||
|
||||
app.get('/articles', article.getAll)
|
||||
app.get('/articles/urls', article.getUrls)
|
||||
app.get('/articles/:slug', article.getItem)
|
||||
|
||||
app.get('/albums', album.getAll)
|
||||
app.get('/albums/urls', album.getUrls)
|
||||
app.get('/albums/:slug', album.getItem)
|
||||
|
||||
app.get('/files', file.getAll)
|
||||
app.get('/files/urls', file.getUrls)
|
||||
app.get('/files/:slug', file.getItem)
|
||||
|
||||
app.get('/pages', page.getAll)
|
||||
app.get('/pages/urls', page.getUrls)
|
||||
app.get('/pages/:slug', page.getItem)
|
||||
|
||||
app.get('/images/:slug', image.getItem)
|
||||
|
||||
app.get('/schedule', schedule.getItem)
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`> Ready on http://localhost:${port}`)
|
||||
})
|
||||
}
|
||||
|
||||
main()
|
||||
Reference in new issue
Block a user