aboutsummaryrefslogtreecommitdiff
path: root/vnext
diff options
context:
space:
mode:
Diffstat (limited to 'vnext')
-rw-r--r--vnext/server/app.js52
-rw-r--r--vnext/server/db/index.js7
-rw-r--r--vnext/server/index.js52
-rw-r--r--vnext/server/middleware/android.spec.js12
-rw-r--r--vnext/server/middleware/mastodon.spec.js8
-rw-r--r--vnext/server/middleware/webfinger.spec.js11
-rw-r--r--vnext/server/sender.js2
7 files changed, 70 insertions, 74 deletions
diff --git a/vnext/server/app.js b/vnext/server/app.js
new file mode 100644
index 00000000..b2ba4cf6
--- /dev/null
+++ b/vnext/server/app.js
@@ -0,0 +1,52 @@
+import express from 'express'
+import { raw } from 'body-parser'
+import cors from 'cors'
+import config from 'config'
+
+//import serverRenderer from './middleware/renderer'
+import event from './middleware/event'
+import oembed from './middleware/oembed'
+import urlExpand from './middleware/urlexpand'
+import releases from './middleware/android'
+import { instance } from './middleware/mastodon'
+
+import path from 'path'
+import { webhook, webhookPath } from './durov'
+import { webfinger } from './middleware/webfinger'
+
+// initialize the application and create the routes
+export const app = express()
+app.use(raw())
+app.use(cors())
+const router = express.Router()
+
+router.post('/api/v2/sender', event)
+router.get('/api/v2/oembed', oembed)
+router.get('/api/v2/urlexpand', urlExpand)
+router.get('/api/apps/android/releases', releases)
+
+// WebFinger
+
+router.get('/.well-known/webfinger', webfinger)
+
+// Mastodon API
+
+router.get('/api/v2/instance', instance)
+
+const durov_webhook = webhookPath()
+if (durov_webhook) {
+ router.post(`/api/v2/${durov_webhook}`, webhook)
+}
+//router.use('^/$', serverRenderer)
+
+const STATIC_ROOT = config.get('service.static_root') || path.resolve(__dirname, 'public')
+
+// other static resources should just be served as they are
+router.use(express.static(
+ STATIC_ROOT,
+ { maxAge: '30d' },
+))
+
+//router.use('*', serverRenderer)
+
+app.use(router)
diff --git a/vnext/server/db/index.js b/vnext/server/db/index.js
index c6c9ca24..9c9e564b 100644
--- a/vnext/server/db/index.js
+++ b/vnext/server/db/index.js
@@ -1,5 +1,10 @@
+import debug from 'debug'
+var log = debug('db')
+
import { Sequelize } from 'sequelize'
-const db = new Sequelize(process.env.DATABASE_URL)
+const db = new Sequelize(process.env.DATABASE_URL, {
+ logging: (...msg) => log(msg)
+})
export default db
diff --git a/vnext/server/index.js b/vnext/server/index.js
index 75b92270..bbb5a578 100644
--- a/vnext/server/index.js
+++ b/vnext/server/index.js
@@ -1,64 +1,14 @@
-import express from 'express'
-import { raw } from 'body-parser'
-import cors from 'cors'
-import config from 'config'
import debug from 'debug'
const log = debug('http')
-//import serverRenderer from './middleware/renderer'
-import event from './middleware/event'
-import oembed from './middleware/oembed'
-import urlExpand from './middleware/urlexpand'
-import releases from './middleware/android'
-import { instance } from './middleware/mastodon'
+import { app } from './app'
const PORT = process.env.LISTEN_PORT || 8081
-import path from 'path'
-import { webhook, webhookPath } from './durov'
-import { webfinger } from './middleware/webfinger'
-
-// initialize the application and create the routes
-const app = express()
-app.use(raw())
-app.use(cors())
-const router = express.Router()
-
-router.post('/api/v2/sender', event)
-router.get('/api/v2/oembed', oembed)
-router.get('/api/v2/urlexpand', urlExpand)
-router.get('/api/apps/android/releases', releases)
-
-// WebFinger
-
-router.get('/.well-known/webfinger', webfinger)
-
-// Mastodon API
-
-router.get('/api/v2/instance', instance)
-
-const durov_webhook = webhookPath()
-if (durov_webhook) {
- router.post(`/api/v2/${durov_webhook}`, webhook)
-}
-//router.use('^/$', serverRenderer)
-
-const STATIC_ROOT = config.get('service.static_root') || path.resolve(__dirname, 'public')
-
-// other static resources should just be served as they are
-router.use(express.static(
- STATIC_ROOT,
- { maxAge: '30d' },
-))
-
-//router.use('*', serverRenderer)
-
-app.use(router)
// start the app
app.listen(PORT, (error) => {
if (error) {
return console.log('something bad happened', error)
}
-
log('listening on ' + PORT + '...')
})
diff --git a/vnext/server/middleware/android.spec.js b/vnext/server/middleware/android.spec.js
index 448714ac..19d380d7 100644
--- a/vnext/server/middleware/android.spec.js
+++ b/vnext/server/middleware/android.spec.js
@@ -1,15 +1,11 @@
import request from 'supertest'
-import express from 'express'
-import releases from './android'
-
-const app = express()
-app.get('/releases', releases)
+import { app } from '../app'
describe('Releases helper', () => {
it('Should respond with empty array to unknown user agents', async () => {
return request(app)
- .get('/releases')
+ .get('/api/apps/android/releases')
.expect(200)
.then(response => {
expect(response.body).toStrictEqual([])
@@ -17,7 +13,7 @@ describe('Releases helper', () => {
})
it('Should respond with a single legacy version data to old Android app', async () => {
return request(app)
- .get('/releases')
+ .get('/api/apps/android/releases')
.set('User-Agent', 'Juick/100 okhttp/3.12 Android/19')
.expect(200)
.then(response => {
@@ -27,7 +23,7 @@ describe('Releases helper', () => {
})
it('Should redirect to Github when Android version is ok', async () => {
return request(app)
- .get('/releases')
+ .get('/api/apps/android/releases')
.set('User-Agent', 'Juick/100 okhttp/3.12 Android/24')
.expect(302)
.then(response => {
diff --git a/vnext/server/middleware/mastodon.spec.js b/vnext/server/middleware/mastodon.spec.js
index 648923e4..561303bc 100644
--- a/vnext/server/middleware/mastodon.spec.js
+++ b/vnext/server/middleware/mastodon.spec.js
@@ -1,14 +1,10 @@
import request from 'supertest'
-import express from 'express'
-import { instance } from './mastodon'
-
-const app = express()
-app.get('/instance', instance)
+import { app } from '../app'
describe('Mastodon API middleware', () => {
it('Inactive users should not be included in Instance response', async () => {
return request(app)
- .get('/instance')
+ .get('/api/v2/instance')
.expect(200)
.then(response => {
expect(response.body.usage.users.active_month).toStrictEqual(1)
diff --git a/vnext/server/middleware/webfinger.spec.js b/vnext/server/middleware/webfinger.spec.js
index fde2e428..efdfff20 100644
--- a/vnext/server/middleware/webfinger.spec.js
+++ b/vnext/server/middleware/webfinger.spec.js
@@ -1,15 +1,12 @@
import request from 'supertest'
-import express from 'express'
-import { webfinger } from './webfinger'
-const app = express()
-app.get('/webfinger', webfinger)
+import { app } from '../app'
describe('WebFinger middleware', () => {
it('Existing user response should have a subject and links', async () => {
const resource = 'acct:ugnich@juick.com'
const response = await request(app)
- .get(`/webfinger?resource=${resource}`)
+ .get(`/.well-known/webfinger?resource=${resource}`)
expect(response.status).toStrictEqual(200)
expect(response.body.subject).toStrictEqual(resource)
expect(response.body.links.length).toStrictEqual(1)
@@ -18,13 +15,13 @@ describe('WebFinger middleware', () => {
it('Unknown user should return 404', async () => {
const resource = 'acct:durov@juick.com'
const response = await request(app)
- .get(`/webfinger?resource=${resource}`)
+ .get(`/.well-known/webfinger?resource=${resource}`)
expect(response.status).toStrictEqual(404)
})
it('Invalid input should return 400', async () => {
const resource = ';DROP TABLE users'
const response = await request(app)
- .get(`/webfinger?resource=${resource}`)
+ .get(`/.well-known/webfinger?resource=${resource}`)
expect(response.status).toStrictEqual(400)
})
})
diff --git a/vnext/server/sender.js b/vnext/server/sender.js
index 257c79f7..d5272bfb 100644
--- a/vnext/server/sender.js
+++ b/vnext/server/sender.js
@@ -24,7 +24,7 @@ const fcmConfig = {
serviceAccountKey: process.env.JUICK_FCM_SERVICE_ACCOUNT_FILE
}
-console.log(`fcm config: ${JSON.stringify(fcmConfig)}`)
+log(`fcm config: ${JSON.stringify(fcmConfig)}`)
const push = new PushNotifications({
...config,