Here's my dev command from package.json
"dev": "NODE_ENV=development nodemon -e 'js,tmpl,css,yml' ./index.js server -l 'http://*:8080'",
I'm getting an error "username is required" when I run locally.
Should just start on 8080
Here is my index.js
:
import mojo, { yamlConfigPlugin } from '@mojojs/core';
import Surreal from 'surrealdb.js';
import { Account } from './models/account.js';
import { Deal } from './models/deal.js';
import { Service } from './models/service.js';
import { Application } from './models/application.js';
import { Inquiry } from './models/inquiry.js';
import dotenv from 'dotenv-flow';
import { add, formatDistanceToNow, format } from 'date-fns';
import { EventEmitter } from 'node:events';
dotenv.config();
export const app = mojo();
const { DB_USER, DB_PASS, DB_NS, DB_DB } = process.env;
app.plugin(yamlConfigPlugin);
app.secrets = app.config.secrets;
app.addAppHook('app:start', async (app) => {
if (!app.models.db) {
app.models.db = new Surreal('http://127.0.0.1:9021/rpc');
await app.models.db.signin({
user: DB_USER,
pass: DB_PASS
});
await app.models.db.use(DB_NS, DB_DB);
}
app.models.account = new Account(app.models.db);
app.models.deals = new Deal(app.models.db);
app.models.service = new Service(app.models.db);
app.models.application = new Application(app.models.db);
app.models.inquiry = new Inquiry(app.models.db);
app.models.events = new EventEmitter();
app.models.events.setMaxListeners(1000);
});
app.addHelper('fromNow', (ctx, str, opts) => formatDistanceToNow(new Date(str), opts));
app.addHelper('time', (ctx, str) => {
return format(new Date(str), 'p');
});
app.addHelper('date', (ctx, str) => {
return format(new Date(str), 'PP');
});
app.addHelper('gigType', (ctx, key) => {
const types = [
{
value: 'fulltime',
label: 'Fulltime'
},
{
value: 'c2c',
label: 'Corp-to-Corp'
},
{
value: 'contract',
label: 'Contract (1099)'
},
{
value: 'internship',
label: 'Internship'
},
{
value: 'parttime',
label: 'Part-time'
}
];
return types.find((item) => item.value === key).label;
});
app.addHelper('serviceType', (ctx, key) => {
const types = [
{
value: 'fulltime',
label: 'Fulltime'
},
{
value: 'c2c',
label: 'Corp-to-Corp'
},
{
value: 'contract',
label: 'Contract (1099)'
},
{
value: 'internship',
label: 'Internship'
},
{
value: 'parttime',
label: 'Part-time'
}
];
return types.find((item) => item.value === key).label;
});
app.get('/').to('index#index').name('index#index');
app.get('/register').to('account#register');
app.post('/register').to('account#create');
app.get('/login').to('account#login').name('account#login');
app.post('/login').to('account#signin');
app.get('/logout').to('account#logout').name('account#logout');
app.get('/deals').to('deals#all').name('deals#all');
app.get('/deals/tags/#tag').to('deals#tag');
app.get('/services').to('services#all').name('services#all');
app.get('/services/tags/#tag').to('services#tag');
app.get('/terms').to('index#terms').name('index#terms');
app.get('/privacy').to('index#privacy').name('index#privacy');
app.post('/noop').to('index#noop');
// guarded pages require logged in user:
const loggedIn = app.under('/').to('account#loggedIn');
// account
loggedIn.get('/account/me').to('account#me').name('account#me');
loggedIn.post('/account/me').to('account#update');
loggedIn.get('/account/users').to('account#users');
loggedIn.get('/account/:username').to('account#one').name('account#one');
loggedIn.get('/verify/email/:code').to('account#verifyEmailCode');
loggedIn.get('/verify/phone/:code').to('account#verifyPhoneCode');
loggedIn.get('/account/resend/email').to('account#resendVerifyEmail').name('account#resendVerifyEmail');
loggedIn.get('/account/resend/phone').to('account#resendVerifyPhone').name('account#resendVerifyPhone');
loggedIn.post('/verify/email/generate').to('account#generateEmailVerifyCode');
loggedIn.post('/verify/phone/generate').to('account#generatePhoneVerifyCode');
// deals
loggedIn.get('/deals/new').to('deals#new').name('deals#new');
loggedIn.get('/deals/:id/edit').to('deals#edit').name('deals#edit');
loggedIn.post('/deals/:id').to('deals#update').name('deals#update');
loggedIn.get('/deals/:id/delete').to('deals#delete');
loggedIn.post('/deals').to('deals#create');
loggedIn.get('/deals/:id/apply').to('deals#apply');
loggedIn.get('/deals/:id/applicants').to('deals#applicants');
// services
loggedIn.get('/services/new').to('services#new').name('services#new');
loggedIn.get('/services/:id/edit').to('services#edit').name('services#edit');
loggedIn.post('/services/:id').to('services#update').name('services#update');
loggedIn.get('/services/:id/delete').to('services#delete');
loggedIn.post('/services').to('services#create');
loggedIn.get('/services/:id/inquire').to('services#inquire');
loggedIn.get('/services/:id/inquiries').to('services#inquiries');
// applications
loggedIn.get('/applications/:id').to('applications#one');
// inquiries
loggedIn.get('/inquiries/:id').to('inquiries#one');
// fall through
app.get('/deals/:id').to('deals#one').name('deals#one');
app.get('/services/:id').to('services#one').name('services#one');
// guarded web sockets
loggedIn.websocket('/application/:id/message').to('applications#message');
loggedIn.websocket('/inquiry/:id/message').to('inquiries#message');
app.start();
So my base controller had some twilio login creds which weren't defined in .env.local
--- adding those fixed the issue. The error message isn't very help that it was from twilio:
import twilio from 'twilio';
const twilioAccountSid = process.env.TWILIO_ACCOUNT_SID;
const twilioAuthToken = process.env.TWILIO_AUTH_TOKEN;
const sms = twilio(twilioAccountSid, twilioAuthToken);