Skip to content

Commit

Permalink
moved passportConfig to src, cleaned up plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
rastenis committed Jul 26, 2019
1 parent 660cfa7 commit b250157
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 18 deletions.
100 changes: 100 additions & 0 deletions config/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
const prompt = require("prompt-sync")({ sigint: true });
const fs = require("fs-extra");

let config = require("./config/configExample.json");
let passportKeys = require("./config/passportKeysExample.json");

fs.ensureDirSync("./db/");

if (process.argv[2]=="--headless") {
// saving defaults
fs.copySync('./config/configExample.json', './config/config.json')
fs.copySync('./config/passportKeysExample.json', './config/passportKeys.json')
process.exit(0);
}

console.log("Hello!");
console.log("Starting setup...");

config.self_hosted =
prompt(
"Use Auto-generated TLS? (will require ports 80 and 443) (y/N): ",
false
).toLowerCase() == "y";

if (config.self_hosted) {
console.log("Showing additional TLS options:");
config.tls.email = prompt("Enter Letsencrypt email (your email): ");
config.tls.tos =
prompt(
"Do you agree with the LetsEncrypt TOS? (Y/n): ",
true
).toLowerCase() == "y";

if (!config.tls.tos) {
config.self_hosted = false;
console.log("Reverting LetsEncrypt setup...");
} else {
let current = 0;
while (true) {
config.tls.domains[current] = prompt(
"Please enter domain " + (current + 1) + " (ENTER to cancel): "
);
if (config.tls.domains[current] == "") {
config.tls.domains.splice(current, 1);
break;
} else {
current++;
}
}
}
}

if (!config.self_hosted) {
config.port = ~~prompt("Enter port (7777): ", config.port);
config.secure_override = ~~prompt(
"Will you use an external HTTPS/TLS provider proxy? Secure cookies will be enabled, if yes (y/N): ",
false
);
}

if (
prompt(
"Do you want to set up Google and Twitter API keys? (Y/n): ",
"Y"
).toLowerCase() == "y"
) {
console.log(
"An external url is required for Google and Twitter auth to function."
);
config.url = prompt(
"Enter your website url: (http://example.com): ",
config.url
);

console.log("Showing additional API KEY information:");
console.log(
"Go to https://console.developers.google.com and create a new project. Then, create credentials for 'OAuth client ID'."
);
passportKeys.GOOGLE_ID = prompt("Paste the Client ID here:");
passportKeys.GOOGLE_SECRET = prompt("Paste the Client secret here:");
console.log("Great!");
console.log(
"Now, go to https://developer.twitter.com/en/apps and create a new twitter app. Navigate to Consumer API keys."
);
passportKeys.TWITTER_KEY = prompt("Paste the API key here:");
passportKeys.TWITTER_SECRET = prompt("Paste the API secret key here:");
console.log("Passport keys configured.");
}

console.log("Setup done. Generating session secret and exiting...");

config.session_secret = [...Array(30)]
.map(i => (~~(Math.random() * 36)).toString(36))
.join("");

// writing and exitting
fs.writeJsonSync("./config/config.json", config);
fs.writeJsonSync("./config/passportKeys.json", passportKeys);

process.exit(0);
3 changes: 2 additions & 1 deletion pages/_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
</template>

<script>
import axios from "~/plugins/axios.js";
import axios from "axios";
export default {
name: "id",
Expand Down
2 changes: 1 addition & 1 deletion pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</template>

<script>
import axios from "~/plugins/axios.js";
import axios from "axios";
export default {
head() {
Expand Down
3 changes: 2 additions & 1 deletion pages/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
</template>

<script>
import axios from "~/plugins/axios.js";
import axios from "axios";
export default {
head() {
Expand Down
3 changes: 2 additions & 1 deletion pages/profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@
</template>

<script>
import axios from "~/plugins/axios.js";
import axios from "axios";
export default {
head() {
Expand Down
3 changes: 2 additions & 1 deletion pages/register.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
</template>

<script>
import axios from "~/plugins/axios.js";
import axios from "axios";
export default {
head() {
Expand Down
6 changes: 0 additions & 6 deletions plugins/axios.js

This file was deleted.

9 changes: 4 additions & 5 deletions config/passportConfig.js → src/passport/passportConfig.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
require("dotenv").config();
const passport = require("passport");
const { Strategy: LocalStrategy } = require("passport-local");
const { Strategy: TwitterStrategy } = require("passport-twitter");
const { OAuth2Strategy: GoogleStrategy } = require("passport-google-oauth");

const db = require("../src/external/db.js");
const keysConf = require("../config/passportKeys.json");
const User = require("../src/controllers/user.js");
const config = require("./config.json");
const db = require("../external/db.js");
const keysConf = require("../../config/passportKeys.json");
const User = require("../controllers/user.js");
const config = require("../../config/config.json");

passport.serializeUser((user, done) => done(null, user.data._id));

Expand Down
2 changes: 1 addition & 1 deletion src/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// deps
"use strict";
process.env.DEBUG = process.env.NODE_ENV === "production" ? "" : "nuxt:*";
const { Nuxt, Builder } = require("nuxt");
const bodyParser = require("body-parser");
Expand Down
1 change: 0 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ test("Login again", async t => {
});

test("Delete account", async t => {
console.log(email);
try {
const { data } = await ax({
method: "post",
Expand Down

0 comments on commit b250157

Please sign in to comment.