cleaning and use nuxt-express
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
# 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.
|
||||
|
||||
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 config_path = process.env.config_path
|
||||
|
||||
let config = {}
|
||||
|
||||
@@ -13,9 +13,9 @@ module.exports = {
|
||||
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }]
|
||||
},
|
||||
dev: (process.env.NODE_ENV !== 'production'),
|
||||
serverMiddleware: [
|
||||
{ path: '/api', handler: '~/server/api/index.js' }
|
||||
],
|
||||
//serverMiddleware: [
|
||||
//{ path: '/api', handler: '~/server/api/index.js' }
|
||||
//],
|
||||
|
||||
server: conf.server,
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
"multer": "^1.4.2",
|
||||
"node-fetch": "^2.6.0",
|
||||
"nuxt": "^2.8.1",
|
||||
"nuxt-express-module": "^0.0.11",
|
||||
"pg": "^7.11.0",
|
||||
"sass-loader": "^7.1.0",
|
||||
"sequelize": "^5.12.3",
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
# 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.
|
||||
|
||||
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')
|
||||
|
||||
module.exports = config.db
|
||||
|
||||
@@ -67,7 +67,7 @@ const Helpers = {
|
||||
|
||||
// TODO: cache
|
||||
async getActor(url, force=false) {
|
||||
// try with cache first if not forced
|
||||
// try with cache first
|
||||
if (!force && actorCache[url]) return actorCache[url]
|
||||
const user = await fetch(url, { headers: {'Accept': 'application/jrd+json, application/json'} })
|
||||
.then(res => {
|
||||
@@ -84,7 +84,7 @@ const Helpers = {
|
||||
// ref: https://blog.joinmastodon.org/2018/07/how-to-make-friends-and-verify-requests/
|
||||
async verifySignature(req, res, next) {
|
||||
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
|
||||
req.headers.authorization = 'Signature ' + req.headers.signature
|
||||
@@ -97,7 +97,7 @@ const Helpers = {
|
||||
|
||||
// signature not valid, try without cache
|
||||
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()
|
||||
|
||||
// still not valid
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
#!/bin/env node
|
||||
const path = require('path')
|
||||
const express = require('express')
|
||||
const consola = require('consola')
|
||||
const morgan = require('morgan')
|
||||
//#!/bin/env node
|
||||
//const path = require('path')
|
||||
//const express = require('express')
|
||||
//const consola = require('consola')
|
||||
//const morgan = require('morgan')
|
||||
const { Nuxt, Builder } = require('nuxt')
|
||||
|
||||
const api = require('./api')
|
||||
const federation = require('./federation')
|
||||
const webfinger = require('./federation/webfinger')
|
||||
//const api = require('./api')
|
||||
//const federation = require('./federation')
|
||||
//const webfinger = require('./federation/webfinger')
|
||||
|
||||
// Import and Set Nuxt.js options
|
||||
const nuxt_config = require('../nuxt.config.js')
|
||||
const config = require('config')
|
||||
|
||||
const app = express()
|
||||
async function start() {
|
||||
nuxt_config.server = config.server
|
||||
// Init Nuxt.js
|
||||
@@ -26,30 +25,31 @@ async function start() {
|
||||
} else {
|
||||
await nuxt.ready()
|
||||
}
|
||||
nuxt.listen()
|
||||
|
||||
// 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('/media/', express.static(config.upload_path))
|
||||
//app.use(morgan('dev'))
|
||||
//app.use('/media/', express.static(config.upload_path))
|
||||
|
||||
// gancio standard api
|
||||
app.use('/api', api)
|
||||
//app.use('/api', api)
|
||||
|
||||
// federation api / activitypub / webfinger / nodeinfo
|
||||
app.use('/.well-known', webfinger)
|
||||
app.use('/federation', federation)
|
||||
//app.use('/.well-known', webfinger)
|
||||
//app.use('/federation', federation)
|
||||
|
||||
// Give nuxt middleware to express
|
||||
app.use(nuxt.render)
|
||||
//app.use(nuxt.render)
|
||||
|
||||
// Listen
|
||||
const server = app.listen(nuxt_config.server)
|
||||
//const server = app.listen(nuxt_config.server)
|
||||
|
||||
// close connections/port/unix socket
|
||||
function shutdown() {
|
||||
consola.info(`Closing connections..`)
|
||||
server.close(() => {
|
||||
nuxt.close(() => {
|
||||
// TODO, close db connection?
|
||||
process.exit()
|
||||
})
|
||||
@@ -57,17 +57,6 @@ async function start() {
|
||||
process.on('SIGTERM', 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()
|
||||
|
||||
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
|
||||
|
||||
**This directory is not required, you can delete it if you don't want to use it.**
|
||||
|
||||
This directory contains your Vuex Store files.
|
||||
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"
|
||||
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:
|
||||
version "2.8.1"
|
||||
resolved "https://registry.yarnpkg.com/nuxt/-/nuxt-2.8.1.tgz#10a307e51973fa7b55abfeb41b84c76cbdd6f2f6"
|
||||
|
||||
Reference in New Issue
Block a user