cleaning and use nuxt-express
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
# ASSETS
|
# ASSETS
|
||||||
|
|
||||||
**This directory is not required, you can delete it if you don't want to use it.**
|
|
||||||
|
|
||||||
This directory contains your un-compiled assets such as LESS, SASS, or JavaScript.
|
This directory contains your un-compiled assets such as LESS, SASS, or JavaScript.
|
||||||
|
|
||||||
More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/assets#webpacked).
|
More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/assets#webpacked).
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
// DO NOT TOUCH THIS FILE
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
|
||||||
const config_path = process.env.config_path
|
const config_path = process.env.config_path
|
||||||
|
|
||||||
let config = {}
|
let config = {}
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ module.exports = {
|
|||||||
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }]
|
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }]
|
||||||
},
|
},
|
||||||
dev: (process.env.NODE_ENV !== 'production'),
|
dev: (process.env.NODE_ENV !== 'production'),
|
||||||
serverMiddleware: [
|
//serverMiddleware: [
|
||||||
{ path: '/api', handler: '~/server/api/index.js' }
|
//{ path: '/api', handler: '~/server/api/index.js' }
|
||||||
],
|
//],
|
||||||
|
|
||||||
server: conf.server,
|
server: conf.server,
|
||||||
|
|
||||||
|
|||||||
@@ -65,6 +65,7 @@
|
|||||||
"multer": "^1.4.2",
|
"multer": "^1.4.2",
|
||||||
"node-fetch": "^2.6.0",
|
"node-fetch": "^2.6.0",
|
||||||
"nuxt": "^2.8.1",
|
"nuxt": "^2.8.1",
|
||||||
|
"nuxt-express-module": "^0.0.11",
|
||||||
"pg": "^7.11.0",
|
"pg": "^7.11.0",
|
||||||
"sass-loader": "^7.1.0",
|
"sass-loader": "^7.1.0",
|
||||||
"sequelize": "^5.12.3",
|
"sequelize": "^5.12.3",
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
# PLUGINS
|
# PLUGINS
|
||||||
|
|
||||||
**This directory is not required, you can delete it if you don't want to use it.**
|
|
||||||
|
|
||||||
This directory contains Javascript plugins that you want to run before mounting the root Vue.js application.
|
This directory contains Javascript plugins that you want to run before mounting the root Vue.js application.
|
||||||
|
|
||||||
More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/plugins).
|
More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/plugins).
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
|
// needed by sequelize
|
||||||
const config = require('config')
|
const config = require('config')
|
||||||
|
|
||||||
module.exports = config.db
|
module.exports = config.db
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ const Helpers = {
|
|||||||
|
|
||||||
// TODO: cache
|
// TODO: cache
|
||||||
async getActor(url, force=false) {
|
async getActor(url, force=false) {
|
||||||
// try with cache first if not forced
|
// try with cache first
|
||||||
if (!force && actorCache[url]) return actorCache[url]
|
if (!force && actorCache[url]) return actorCache[url]
|
||||||
const user = await fetch(url, { headers: {'Accept': 'application/jrd+json, application/json'} })
|
const user = await fetch(url, { headers: {'Accept': 'application/jrd+json, application/json'} })
|
||||||
.then(res => {
|
.then(res => {
|
||||||
@@ -84,7 +84,7 @@ const Helpers = {
|
|||||||
// ref: https://blog.joinmastodon.org/2018/07/how-to-make-friends-and-verify-requests/
|
// ref: https://blog.joinmastodon.org/2018/07/how-to-make-friends-and-verify-requests/
|
||||||
async verifySignature(req, res, next) {
|
async verifySignature(req, res, next) {
|
||||||
let user = await Helpers.getActor(req.body.actor)
|
let user = await Helpers.getActor(req.body.actor)
|
||||||
if (!user) return res.send('Actor not found', 401)
|
if (!user) return res.status(401).send('Actor not found')
|
||||||
|
|
||||||
// little hack -> https://github.com/joyent/node-http-signature/pull/83
|
// little hack -> https://github.com/joyent/node-http-signature/pull/83
|
||||||
req.headers.authorization = 'Signature ' + req.headers.signature
|
req.headers.authorization = 'Signature ' + req.headers.signature
|
||||||
@@ -97,7 +97,7 @@ const Helpers = {
|
|||||||
|
|
||||||
// signature not valid, try without cache
|
// signature not valid, try without cache
|
||||||
user = await Helpers.getActor(req.body.actor, true)
|
user = await Helpers.getActor(req.body.actor, true)
|
||||||
if (!user) return res.send('Actor not found', 401)
|
if (!user) return res.status(401).send('Actor not found')
|
||||||
if (httpSignature.verifySignature(parsed, user.publicKey.publicKeyPem)) return next()
|
if (httpSignature.verifySignature(parsed, user.publicKey.publicKeyPem)) return next()
|
||||||
|
|
||||||
// still not valid
|
// still not valid
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
#!/bin/env node
|
//#!/bin/env node
|
||||||
const path = require('path')
|
//const path = require('path')
|
||||||
const express = require('express')
|
//const express = require('express')
|
||||||
const consola = require('consola')
|
//const consola = require('consola')
|
||||||
const morgan = require('morgan')
|
//const morgan = require('morgan')
|
||||||
const { Nuxt, Builder } = require('nuxt')
|
const { Nuxt, Builder } = require('nuxt')
|
||||||
|
|
||||||
const api = require('./api')
|
//const api = require('./api')
|
||||||
const federation = require('./federation')
|
//const federation = require('./federation')
|
||||||
const webfinger = require('./federation/webfinger')
|
//const webfinger = require('./federation/webfinger')
|
||||||
|
|
||||||
// Import and Set Nuxt.js options
|
// Import and Set Nuxt.js options
|
||||||
const nuxt_config = require('../nuxt.config.js')
|
const nuxt_config = require('../nuxt.config.js')
|
||||||
const config = require('config')
|
const config = require('config')
|
||||||
|
|
||||||
const app = express()
|
|
||||||
async function start() {
|
async function start() {
|
||||||
nuxt_config.server = config.server
|
nuxt_config.server = config.server
|
||||||
// Init Nuxt.js
|
// Init Nuxt.js
|
||||||
@@ -26,30 +25,31 @@ async function start() {
|
|||||||
} else {
|
} else {
|
||||||
await nuxt.ready()
|
await nuxt.ready()
|
||||||
}
|
}
|
||||||
|
nuxt.listen()
|
||||||
|
|
||||||
// configurable favicon && logo
|
// configurable favicon && logo
|
||||||
app.use('/favicon.ico', express.static(path.resolve(config.favicon || 'assets/favicon.ico')))
|
//app.use('/favicon.ico', express.static(path.resolve(config.favicon || 'assets/favicon.ico')))
|
||||||
|
|
||||||
app.use(morgan('dev'))
|
//app.use(morgan('dev'))
|
||||||
app.use('/media/', express.static(config.upload_path))
|
//app.use('/media/', express.static(config.upload_path))
|
||||||
|
|
||||||
// gancio standard api
|
// gancio standard api
|
||||||
app.use('/api', api)
|
//app.use('/api', api)
|
||||||
|
|
||||||
// federation api / activitypub / webfinger / nodeinfo
|
// federation api / activitypub / webfinger / nodeinfo
|
||||||
app.use('/.well-known', webfinger)
|
//app.use('/.well-known', webfinger)
|
||||||
app.use('/federation', federation)
|
//app.use('/federation', federation)
|
||||||
|
|
||||||
// Give nuxt middleware to express
|
// Give nuxt middleware to express
|
||||||
app.use(nuxt.render)
|
//app.use(nuxt.render)
|
||||||
|
|
||||||
// Listen
|
// Listen
|
||||||
const server = app.listen(nuxt_config.server)
|
//const server = app.listen(nuxt_config.server)
|
||||||
|
|
||||||
// close connections/port/unix socket
|
// close connections/port/unix socket
|
||||||
function shutdown() {
|
function shutdown() {
|
||||||
consola.info(`Closing connections..`)
|
consola.info(`Closing connections..`)
|
||||||
server.close(() => {
|
nuxt.close(() => {
|
||||||
// TODO, close db connection?
|
// TODO, close db connection?
|
||||||
process.exit()
|
process.exit()
|
||||||
})
|
})
|
||||||
@@ -57,17 +57,6 @@ async function start() {
|
|||||||
process.on('SIGTERM', shutdown)
|
process.on('SIGTERM', shutdown)
|
||||||
process.on('SIGINT', shutdown)
|
process.on('SIGINT', shutdown)
|
||||||
|
|
||||||
server.on('error', e => {
|
|
||||||
consola.error(e)
|
|
||||||
})
|
|
||||||
|
|
||||||
server.on('listening', () => {
|
|
||||||
const address = server.address()
|
|
||||||
consola.ready({
|
|
||||||
message: `Server listening on ${(typeof address) === 'object' ? `${address.address}:${address.port}` : address}`,
|
|
||||||
badge: true
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
start()
|
start()
|
||||||
|
|||||||
17
server/routes.js
Normal file
17
server/routes.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
const path = require('path')
|
||||||
|
const config = require('config')
|
||||||
|
const express = require('express')
|
||||||
|
const api = require('./api')
|
||||||
|
const federation = require('./federation')
|
||||||
|
const webfinger = require('./federation/webfinger')
|
||||||
|
|
||||||
|
const router = express.Router()
|
||||||
|
router.use('/favicon.ico', express.static(path.resolve(config.favicon || 'assets/favicon.ico')))
|
||||||
|
router.use('/media/', express.static(config.upload_path))
|
||||||
|
router.use('/api', api)
|
||||||
|
|
||||||
|
// federation api / activitypub / webfinger / nodeinfo
|
||||||
|
router.use('/.well-known', webfinger)
|
||||||
|
router.use('/federation', federation)
|
||||||
|
|
||||||
|
module.exports = router
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
# STORE
|
# STORE
|
||||||
|
|
||||||
**This directory is not required, you can delete it if you don't want to use it.**
|
|
||||||
|
|
||||||
This directory contains your Vuex Store files.
|
This directory contains your Vuex Store files.
|
||||||
Vuex Store option is implemented in the Nuxt.js framework.
|
Vuex Store option is implemented in the Nuxt.js framework.
|
||||||
|
|
||||||
|
|||||||
@@ -6787,6 +6787,13 @@ number-is-nan@^1.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d"
|
resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d"
|
||||||
integrity sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=
|
integrity sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=
|
||||||
|
|
||||||
|
nuxt-express-module@^0.0.11:
|
||||||
|
version "0.0.11"
|
||||||
|
resolved "https://registry.yarnpkg.com/nuxt-express-module/-/nuxt-express-module-0.0.11.tgz#d78375b52b8a7529bc06b110d3c81b30416f09b5"
|
||||||
|
integrity sha512-ugLUMqKhOFVt55lbpBTLrfVHxCeKCq6jqsyQcZ1+nh5eQnb8hm5T4xF+Ud0g2jzuMXLUgKM9dyIU1rv5VdMuKg==
|
||||||
|
dependencies:
|
||||||
|
express "^4.16.3"
|
||||||
|
|
||||||
nuxt@^2.8.1:
|
nuxt@^2.8.1:
|
||||||
version "2.8.1"
|
version "2.8.1"
|
||||||
resolved "https://registry.yarnpkg.com/nuxt/-/nuxt-2.8.1.tgz#10a307e51973fa7b55abfeb41b84c76cbdd6f2f6"
|
resolved "https://registry.yarnpkg.com/nuxt/-/nuxt-2.8.1.tgz#10a307e51973fa7b55abfeb41b84c76cbdd6f2f6"
|
||||||
|
|||||||
Reference in New Issue
Block a user