Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const bodyParser = require('body-parser');
- const cors = require('cors');
- const r = require('rethinkdbdash')({ db: 'tm_tieto' });
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
- const settings = {
- secret: 'd7cad03d66f2d263991b2412dc112b7e',
- site: {
- name: 'Tm-Tieto Oy',
- url: 'http://localhost:3000'
- },
- email: {
- from: "no-reply@tm-tieto.fi",
- host: "mail.smtp2go.com",
- user: "test@email.com",
- password: "azFjM3BkbjhzcDAw",
- ssl: true
- }
- };
- const app = express();
- app.use(cors());
- app.use(bodyParser.json())
- .use(bodyParser.urlencoded({ extended: false }));
- const auth = require('chaos-auth')(r, settings);
- const apiRoutes = express.Router();
- app.use('/auth', auth.router);
- app.get('/test', auth.authorize, (req, res) => {
- console.log('test works');
- res.send({ success: true, message: 'i am authorized' });
- });
- require('./controllers/assets')(r, apiRoutes, auth);
- require('./controllers/environment_cards')(r, apiRoutes, auth);
- require('./controllers/customer_types')(r, apiRoutes, auth);
- require('./controllers/users')(r, apiRoutes, auth);
- require('./controllers/organizations')(r, apiRoutes, auth);
- app.use('/v1', apiRoutes);
- // Basic Request Logger
- app.use((req, res, next) => {
- console.log(new Date(), req.method, req.path);
- next();
- });
- // Attach your endpoints/controllers here
- app.listen(3000, () => {
- console.log(`The API is running on port 3000`);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement