-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
56 lines (46 loc) · 1.66 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import express from 'express'
import pkg from 'morgan'
import { url, key } from './src/constants.js'
import bodyParser from 'body-parser'
import wellKnownRouter from './src/routes/wellKnown.js'
import { actorRouter } from './src/routes/actor.js'
import { postDeleteRoute, postPublishRoute } from './src/routes/post.js'
import { profileRoute } from './src/routes/profile.js'
import { router as tagsRouter } from './src/routes/tags.js'
const logger = pkg
const app = express()
app.use(logger('dev'))
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.use(bodyParser.json({ type: 'application/activity+json' })) // support json encoded bodies
try {
app.set('apiKey', key.api)
} catch (err) {
console.error('ERROR: Could not load API key\n', err)
process.exit(1)
}
app.use((req, res, next) => {
res.append('Access-Control-Allow-Origin', ['*'])
res.append('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
res.append('Access-Control-Allow-Headers', 'Content-Type')
next()
})
app.use('/.well-known', wellKnownRouter)
app.get(`${url.path.actor}/${process.env.ACCOUNT_USERNAME}.json`, profileRoute)
app.use(`${url.path.actor}/${process.env.ACCOUNT_USERNAME}`, actorRouter)
app.use(url.path.staticImages, express.static('img'))
app.use(url.path.publish, express.Router().post('/', postPublishRoute))
app.use(url.path.delete, express.Router().post('/', postDeleteRoute))
app.use(url.path.tags, tagsRouter)
app.get('/', (req, res) => {
res.redirect(url.profile)
})
app.get('*', (req, res) => {
res.status(404)
res.send('Resource not found')
})
app.post('*', (req, res) => {
res.status(404)
res.send('Resource not found')
})
export default app