Skip to content

Commit

Permalink
upgrade code
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleguido committed Feb 15, 2024
1 parent 5355f12 commit 54d6919
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 27 deletions.
37 changes: 31 additions & 6 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const path = require('path')
const debug = require('debug')('impresso:app')
const compress = require('compression')
const cors = require('cors')
const helmet = require('helmet')
const bodyParser = require('body-parser')
const cookieParser = require('cookie-parser')

const feathers = require('@feathersjs/feathers')
Expand Down Expand Up @@ -32,14 +33,16 @@ app.configure(configuration())
app.use(cors())
app.use(helmet())
app.use(compress())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
// Turn on JSON parser for REST services
app.use(express.json())
// Turn on URL-encoded parser for REST services
app.use(express.urlencoded({ extended: true }))
// app.use(bodyParser.json())
// app.use(bodyParser.urlencoded({ extended: true }))
app.use(cookieParser())
// app.use(favicon(path.join(app.get('public'), 'favicon.ico')))
// Host the public folder
app.use('/', express.static(app.get('public')))

app.configure(socketio())
app.use('/', express.static(path.join(__dirname, app.get('public'))))

// configure database adapters
app.configure(sequelize)
Expand Down Expand Up @@ -116,5 +119,27 @@ app.use(
})
)
app.configure(appHooks)
// Register REST service handler
debug('registering rest handler')
app.configure(
socketio((io) => {
debug('registering socketio handler')
io.on('connection', (socket) => {
// Do something here
debug('socket connected')
})
io.on('disconnect', (socket) => {
// Do something here
debug('socket disconnected')
})

// Registering Socket.io middleware
io.use(function (socket, next) {
// Exposing a request property to services and hooks
socket.feathers.referrer = socket.request.referrer
next()
})
})
)
app.configure(express.rest())
module.exports = app
2 changes: 1 addition & 1 deletion src/celery.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const getCeleryClient = (config, app) => {

module.exports = function (app) {
const config = app.get('celery');
if (!config || !config.enable) {
if (!config?.enable) {
debug('Celery is not configured. No task management is available.');
app.set('celeryClient', null);
} else {
Expand Down
33 changes: 21 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,30 @@ const app = require('./app')
const port = app.get('port')
const host = app.get('host')

debug(`Server: starting on http://${host}:${port}...`)
process.on('unhandledRejection', (reason) => {
// show track
debug(
'process@unhandledRejection:',
reason.message,
'err:',
reason.stack || reason
)
})
process.on('uncaughtException', (err) => {
debug('process@uncaughtException:', err)
})

async function start() {
const server = await app.listen(port)
process.on('unhandledRejection', (reason) => {
// show track
debug(
'process@unhandledRejection:',
reason.message,
'err:',
reason.stack || reason
)
debug(`Server: starting on http://${host}:${port}...`)
const server = await app.listen(port, () => {
debug(`Server @listening application started on http://${host}:${port}`)
})
server.on('listening', () => {
debug(`server@listening application started on http://${host}:${port}`)

server.on('error', (err) => {
debug('server@error:', err)
})
server.on('close', () => {
debug('server@close:', 'server closed')
})
}
start()
16 changes: 8 additions & 8 deletions src/services/articles/articles.service.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
// Initializes the `articles` service on path `/articles`
const createService = require('./articles.class.js');
const hooks = require('./articles.hooks');
const createService = require('./articles.class')
const hooks = require('./articles.hooks')

module.exports = function (app) {
const paginate = app.get('paginate');
const paginate = app.get('paginate')

const options = {
name: 'articles',
paginate,
// need to pass config and queries to neo4j.service
config: app.get('neo4j'),
app,
};
}

// Initialize our service with any options it requires
app.use('/articles', createService(options));
app.use('/articles', createService(options))

// Get our initialized service so that we can register hooks and filters
const service = app.service('articles');
const service = app.service('articles')

service.hooks(hooks);
};
service.hooks(hooks)
}

0 comments on commit 54d6919

Please sign in to comment.