UNPKG

postelf

Version:

a web based solution for email server/client based on postfix

92 lines (66 loc) 2.73 kB
const path = require('path'); const favicon = require('serve-favicon'); const compress = require('compression'); const helmet = require('helmet'); const cors = require('cors'); const logger = require('./logger'); const feathers = require('@feathersjs/feathers'); const configuration = require('@feathersjs/configuration'); const express = require('@feathersjs/express'); const socketio = require('@feathersjs/socketio'); const middleware = require('./middleware'); const services = require('./services'); const appHooks = require('./app.hooks'); const channels = require('./channels'); const app = express(feathers()); const authentication = require('@feathersjs/authentication'); const local = require('@feathersjs/authentication-local'); // Load app configuration app.configure(configuration()); // Enable security, CORS, compression, favicon and body parsing app.use(helmet()); app.use(cors()); app.use(compress()); app.use(express.json()); app.use(express.urlencoded({ extended: true })); app.use(favicon(path.join(app.get('public'), 'favicon.ico'))); // Host the public folder app.use('/', express.static(app.get('public'))); // Set up Plugins and providers app.configure(express.rest()); app.configure(socketio()); // Configure other middleware (see `middleware/index.js`) app.configure(middleware); // Set up our services (see `services/index.js`) // Setup authentication app.configure(authentication({ name: 'local', // the name to use when invoking the authentication Strategy entity: 'user', // the entity that you're comparing username/password against service: 'users', // the service to look up the entity usernameField: 'email', // key name of username field passwordField: 'password', // key name of password field entityUsernameField: 'email', // key name of the username field on the entity (defaults to `usernameField`) entityPasswordField: 'password', // key name of the password on the entity (defaults to `passwordField`) passReqToCallback: true, // whether the request object should be passed to `verify` session: false, // whether to use sessions, secret:'nc18441900', })); app.configure(local()); app.configure(services); // Set up event channels (see channels.js) app.configure(channels); // Configure a middleware for 404s and the error handler app.use(express.notFound()); app.use(express.errorHandler({ logger })); // Setup a hook to only allow valid JWTs or successful // local auth to authenticate and get new JWT access tokens app.service('authentication').hooks({ before: { create: [ authentication.hooks.authenticate(['local', 'jwt']) ] } }); app.hooks(appHooks); module.exports = app; console.log("server started");