Hereās my index.js
file:///home/chris/testServer20230528-2/ourhangoutsapp/index.js:291
adapter: new PushAdapter(pushOptions),
If I can just get past that, I should be good.
Itās probably simpler if someone can tell me how to use an import the way one can use a require.
/**
*/
// Example express application adding the parse-server module to expose Parse
// compatible API routes.
// const express = require(āexpressā);
import express from āexpressā;
// const ParseServer = require(āparse-serverā).ParseServer;
import { ParseServer } from āparse-serverā;
// const path = require(āpathā);
import path from āpathā;
const __dirname = path.resolve();
import http from āhttpā;
// const utils = require("./utils");
// import { utils } from ā./utils.jsā;
// const PushAdapter = require(ā@parse/push-adapterā).default;
// import { PushAdapter } from ā@parse/push-adapterā;
// CANT get this to work !!! need to say new
import pkg from ā@parse/push-adapterā;
const { PushAdapter } = pkg;
/**
- Basic Parameters
*/
const serverUrl = process.env.SERVER_URL;
const databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
const publicHtmlURL = serverUrl + ā/node_modules/parse-server/public_htmlā;
const appPort = 1337;
/**
- Parse Server Push Adapter
*/
const verboseParseServerPushAdapter = parseInt(process.env.VERBOSE_PARSE_SERVER_PUSH_ADAPTER) || 1;
/**
- Apple Push Notification Parameters
*/
const pushIosAppleP8FilePath = process.env.PUSH_IOS_KEY_PATH;
const pushIosKeyId = process.env.PUSH_IOS_KEYID;
const pushIosTeamId = process.env.PUSH_IOS_TEAMID;
const pushIosTopic = process.env.PUSH_IOS_TOPIC;
// bool_value = value == ātrueā ? true : false No such thing as parseBoolean
const pushIosProduction = process.env.PUSH_IOS_PRODUCTION == ātrueā ? true : false;
/**
- Mail for Password Reset and Account Verification Parameters
*/
const mailFromAddress = process.env.MAIL_FROM_ADDRESS;
const mailUser = process.env.MAIL_USER;
const mailPassword = process.env.MAIL_PASSWORD;
const mailHost = process.env.MAIL_HOST;
const mailPort = parseInt(process.env.MAIL_PORT);
const mailName = process.env.MAIL_NAME;
const mailResetSubject = process.env.MAIL_RESET_SUBJECT;
const mailVerifySubject = process.env.MAIL_VERIFY_SUBJECT;
// Prevent user from logging in if email not verified
// preventLoginWithUnverifiedEmail = mailPreventUnverified
const mailPreventUnverified = process.env.MAIL_PREVENT_UNVERIFIED == ātrueā ? true : false;
// Send our verification request emails
const mailVerifyUserEmails = process.env.MAIL_VERIFY_USER_EMAILS == ātrueā ? true : false;
// Set this if the e mail address to send to is other than
// the āemainā column in the DB. Then uncomment mailEmailField in the
// emailAdapter config section
// var mailEmailField = process.env.MAIL_EMAIL_FIELD;
/**
- TLS/SSL for sending mail
*/
// bool_value = value == ātrueā ? true : false - No such thing as parseBoolean
const mailIsSsl = process.env.MAIL_IS_SSL == ātrueā ? true : false;
const nodeExtraCaCerts = process.env.NODE_EXTRA_CA_CERTS;
const nodeTlsRejectUnauthorized = parseInt(process.env.NODE_TLS_REJECT_UNAUTHORIZED);
const openSslConf = process.env.OPENSSL_CONF
/**
- Push Adapter Setup
-
GitHub - parse-community/parse-server-push-adapter: Official Push adapter for parse-server
*/
// const PushAdapter = require(ā@parse/push-adapterā).default;
const pushOptions = {
ios: {
token: {
key: pushIosAppleP8FilePath,
keyId: pushIosKeyId,
teamId: pushIosTeamId // The Team ID for your developer account
},
topic: pushIosTopic, // The bundle identifier associated with your app
production: pushIosProduction
}
// Add Android Options here.
}
/**
- ShowVars
- Show all variables defined
*/
function showParams(x, y) {
const stuff = `
Basoc Parameters
SERVER_URLā¦${serverUrl}
DATABASE_URIā¦${databaseUri}
publicHtmlURLā¦${publicHtmlURL}
appPortā¦${appPort}
Parse Server Push Adapter
VERBOSE_PARSE_SERVER_PUSH_ADAPTERā¦${verboseParseServerPushAdapter}
Apple Push Notification Parameters
PUSH_IOS_KEY_PATHā¦${pushIosAppleP8FilePath}
PUSH_IOS_KEYIDā¦${pushIosKeyId}
IMPORTANT:
PUSH_IOS_KEYID should match the Q7NG4G83K9 part in PUSH_IOS_KEY_PATHs filename, AuthKey_Q7NG4G83K9.p8
PUSH_IOS_TEAMIDā¦${pushIosTeamId}
PUSH_IOS_TOPICā¦${pushIosTopic}
PUSH_IOS_PRODUCTIONā¦${pushIosProduction}
Mail for Password Reset and Account Verification Parameters
MAIL_FROM_ADDRESSā¦${mailFromAddress}
MAIL_USERā¦${mailUser}
MAIL_PASSWORDā¦${mailPassword}
MAIL_HOSTā¦${mailHost}
MAIL_PORTā¦${mailPort}
MAIL_NAMEā¦${mailName}
MAIL_RESET_SUBJECTā¦${mailResetSubject}
MAIL_VERIFY_SUBJECTā¦${mailVerifySubject}
prevent unverified logins
MAIL_PREVENT_UNVERIFIEDā¦${mailPreventUnverified}
send verification emails for new users
MAIL_VERIFY_USER_EMAILSā¦${mailVerifyUserEmails}
TLS/SSL for sending mail
MAIL_IS_SSLā¦${mailIsSsl}
NODE_EXTRA_CA_CERTSā¦${nodeExtraCaCerts}
NODE_TLS_REJECT_UNAUTHORIZEDā¦${nodeTlsRejectUnauthorized}
TLS gets a wrong version number. FIgure this out.
What should this value be??? is undefined.
OPENSSL_CONFā¦${openSslConf}
IMPORTANT: Paths on FakeHeroku vs Real Heroku are different.
Heroku uses a container, Path starts: /app/certs/ā¦
FakeHeroku uses nothing, Path starts: /home/chris/heroku-server/parse-server-example/certs/ā¦
Currently the root directory is: ${__dirname}
`
console.log(stuff);
}
// Switch this off for prod
showParams()
/**
- Setup the Parse Server
- Some note someplace saidā¦
- āstarting 3.0.0ā
-
- Is this what version we are??? Parse
*/
var api = new ParseServer({
// Oct 28 2022 - Suggenly Parse Signup returns File upload by public is disabled
// Allowing public file upload fixes this.
fileUpload: {enableForPublic: true,},
databaseURI: databaseUri,
cloud: process.env.CLOUD_CODE_MAIN || __dirname + ā/cloud/main.jsā,
appId: process.env.APP_ID || āmyAppIdā,
masterKey: process.env.MASTER_KEY || āā, //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || āhttp://localhost:1337/parseā, // Donāt forget to change to https if needed
liveQuery: {
classNames: [āPostsā, āCommentsā] // List of classes to support for query subscriptions
},
//This is the config for email adapter
appName: āOurHangoutsā,
// publicServerURL: āhttp://localhost:1337/parseā,
publicServerURL: serverUrl,
port: appPort,
// See GitHub - parse-community/parse-server: Parse Server for Node.js / Express
// The account lock policy
accountLockout: {
// Lock the account for 5 minutes.
duration: 5,
// Lock an account after 3 failed log-in attempts
threshold: 3,
// Unlock the account after a successful password reset
unlockOnPasswordReset: true,
},
// The password policy
passwordPolicy: {
// Enforce a password of at least 8 characters which contain at least 1 lower case, 1 upper case and 1 digit
validatorPattern: /^(?=.[a-z])(?=.[A-Z])(?=.*[0-9])(?=.{8,})/,
// Do not allow the username as part of the password
doNotAllowUsername: true,
// Do not allow to re-use the last 5 passwords when setting a new password
maxPasswordHistory: 5,
},
// See GitHub - parse-community/parse-server: Parse Server for Node.js / Express
// under Email verification and Password reset
/*
Verifying user email addresses and enabling password reset via email requires
an email adapter. As part of the parse-server package we provide an adapter
for sending email through Mailgun. To use it, sign up for Mailgun, and add this
to your initialization code:
*/
// Enable email verification
// SET TO TRUE when ready
verifyUserEmails: mailVerifyUserEmails,
// if verifyUserEmails is true and
// if emailVerifyTokenValidityDuration is undefined then
// email verify token never expires
// else
// email verify token expires after emailVerifyTokenValidityDuration
//
// emailVerifyTokenValidityDuration defaults to undefined
//
// email verify token below expires in 2 hours (= 2 * 60 * 60 == 7200 seconds)
emailVerifyTokenValidityDuration: 2 * 60 * 60, // in seconds (2 hours = 7200 seconds)
// set preventLoginWithUnverifiedEmail to false to allow user to login without verifying their email
// set preventLoginWithUnverifiedEmail to true to prevent user from login if their email is not verified
preventLoginWithUnverifiedEmail: mailPreventUnverified, // defaults to false
// The public URL of your app.
// This will appear in the link that is used to verify email addresses and reset passwords.
// Set the mount path as it is in serverURL serverUrl
// publicServerURL: āhttps://example.com/parseā,
// see above
// The Parse Simple SMTP mail adapter - start
emailAdapter: {
module: āsimple-parse-smtp-adapterā,
options: {
fromAddress: mailFromAddress,
user: mailUser,
password: mailPassword,
host: mailHost,
isSSL: mailIsSsl, //True or false if you are using ssl
port: mailPort, //SSL port or another port
name: mailName, // optional, used for identifying to the server
//Somtimes the user email is not in the āemailā field, the email is search first in
//email field, then in username field, if you have the user email in another field
//You can specify here
// THIS IS A FIELD in the USER TABLE. READ ABOVE CAREFULLY.
// WE ARE FINE WITH USING THE EXISTING FIELD, SO DONāt DEFINE.
// emailField: mailEmailField,
templates: {
//This template is used only for reset password email
resetPassword: {
//Path to your template
template: __dirname + ā/views/email/reset-passwordā,
//Subject for this email
subject: mailResetSubject
},
verifyEmail: {
template: __dirname + ā/views/email/verify-emailā,
subject: mailVerifySubject
}
}
}
},
// The Parse Simple SMTP mail adapter - end
// parse-server-push-adapter
// GitHub - parse-community/parse-server-push-adapter: Official Push adapter for parse-server
push: {
adapter: new PushAdapter(pushOptions),
}
});
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey
var app = express();
// Serve static assets from the /public folder
app.use(ā/publicā, express.static(path.join(__dirname, ā/publicā)));
// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || ā/parseā;
app.use(mountPath, api);
// Parse Server plays nicely with the rest of your web routes
app.get(ā/ā, function(req, res) {
res.status(200).send(āWelcome to the OurHangouts Backend.ā);
});
// There will be a test page available on the /test path of your server url
// Remove this before launching your app
// app.get(ā/testā, function(req, res) {
// res.sendFile(path.join(__dirname, ā/public/test.htmlā));
//});
var port = process.env.PORT || 1337;
var httpServer = require(āhttpā).createServer(app);
httpServer.listen(port, function() {
console.log('OurHangouts backend based on parse-server-example running on port ā + port + ā.ā);
});
// This will enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer);