Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Fix hardcoded server URLs in client #117

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import cookieParser from 'cookie-parser';

dotenv.config();

const PORT = process.env.PORT || 3000;
const HOST = process.env.HOST || 'localhost';
const server = express();

server.use(cookieParser());
Expand Down Expand Up @@ -62,7 +60,8 @@ function renderEjsAt(filePath, route) {
{
params: {
...req.params,
server_url: process.env.SERVER,
server_url: process.env.SERVER_URL,
server_api: process.env.SERVER_API,
cookies: req.cookies,
},
},
Expand Down Expand Up @@ -90,6 +89,9 @@ routes.forEach(([file, route]) => renderEjsAt(file, route));

server.use(express.static('public'));

const PORT = process.env.PORT || 3000;
const HOST = process.env.HOST || 'localhost';

server.listen(PORT, HOST, () => {
console.log(`Serving ejs from ${PORT}`);
});
4 changes: 3 additions & 1 deletion client/template.env
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
PORT=3000
PORT=8000
SERVER_URL=http://localhost:3000
SERVER_API=http://api.localhost:3000
5 changes: 3 additions & 2 deletions client/views/admin/create/index.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<%- await include("../../layouts/header.ejs", {title: 'FLUX ADMIN'}) %>
<%- await include("../../partials/admin/user-create.ejs") %>

<%- await include("../../partials/admin/user-create.ejs", {params: params}) %>


<%- await include("../../layouts/footer.ejs") %>
</body>
</html>
</html>
4 changes: 2 additions & 2 deletions client/views/admin/tokenplans/index.ejs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<%- await include("../../layouts/header.ejs", {title: 'FLUX ADMIN'}) %>
<%- await include("../../partials/admin/token-plans-create.ejs") %>
<%- await include("../../partials/admin/token-plans-create.ejs", {params: params}) %>


<%- await include("../../layouts/footer.ejs") %>
</body>

</html>
</html>
4 changes: 2 additions & 2 deletions client/views/components/space/main.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<div class="modal-box">
<h3 class="font-bold text-lg">Create Folder</h3>
<p class="py-4">Please enter the name of the folder</p>
<!-- <form action="https://api.flux.codegasms.com/spaces/create" method="POST" enctype="multipart/form-data" onsubmit="prependPwd()"> -->
<!-- <form action="<%- params.server_api %>/spaces/create" method="POST" enctype="multipart/form-data" onsubmit="prependPwd()"> -->
<!-- <input type="hidden" name="variable" id="spaceParentForm" value="<%#=pwd ? pwd : "/"%>"> -->
<input type="text" required placeholder="Folder name" class="input input-bordered w-full max-w-xs mx-3" id="folderName" name="spaceParent" />
<button type="submit" class="btn btn-primary createFolder" id="<%=pwd ? pwd : "/"%>"> Create </button>
Expand Down Expand Up @@ -226,4 +226,4 @@
</div>
</div>
</div>
</div>
</div>
10 changes: 5 additions & 5 deletions client/views/login/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<h1 class="text-2xl xl:text-3xl font-extrabold">Sign In</h1>
<div class="w-full flex-1 mt-8">
<div class="flex flex-col items-center">
<button class="w-full max-w-xs font-bold shadow-sm rounded-lg py-3 bg-indigo-100 text-gray-800 flex items-center justify-center transition-all duration-300 ease-in-out focus:outline-none hover:shadow focus:shadow-sm focus:shadow-outline" onclick="window.location.href='https://api.flux.codegasms.com/oauth/google'">
<button class="w-full max-w-xs font-bold shadow-sm rounded-lg py-3 bg-indigo-100 text-gray-800 flex items-center justify-center transition-all duration-300 ease-in-out focus:outline-none hover:shadow focus:shadow-sm focus:shadow-outline" onclick="window.location.href='<%- params.server_api %>/oauth/google'">
<div class="bg-white p-2 rounded-full">
<svg class="w-4" viewBox="0 0 533.5 544.3">
<path d="M533.5 278.4c0-18.5-1.5-37.1-4.7-55.3H272.1v104.8h147c-6.1 33.8-25.7 63.7-54.4 82.7v68h87.7c51.5-47.4 81.1-117.4 81.1-200.2z" fill="#4285f4" />
Expand All @@ -20,7 +20,7 @@
<span class="ml-4"> Sign In with Google </span>
</button>

<button class="w-full max-w-xs font-bold shadow-sm rounded-lg py-3 bg-indigo-100 text-gray-800 flex items-center justify-center transition-all duration-300 ease-in-out focus:outline-none hover:shadow focus:shadow-sm focus:shadow-outline mt-5" onclick="window.location.href='https://api.flux.codegasms.com/oauth/github'">
<button class="w-full max-w-xs font-bold shadow-sm rounded-lg py-3 bg-indigo-100 text-gray-800 flex items-center justify-center transition-all duration-300 ease-in-out focus:outline-none hover:shadow focus:shadow-sm focus:shadow-outline mt-5" onclick="window.location.href='<%- params.server_api %>/oauth/github'">
<div class="bg-white p-1 rounded-full">
<svg class="w-6" viewBox="0 0 32 32">
<path fill-rule="evenodd" d="M16 4C9.371 4 4 9.371 4 16c0 5.3 3.438 9.8 8.207 11.387.602.11.82-.258.82-.578 0-.286-.011-1.04-.015-2.04-3.34.723-4.043-1.609-4.043-1.609-.547-1.387-1.332-1.758-1.332-1.758-1.09-.742.082-.726.082-.726 1.203.086 1.836 1.234 1.836 1.234 1.07 1.836 2.808 1.305 3.492 1 .11-.777.422-1.305.762-1.605-2.664-.301-5.465-1.332-5.465-5.93 0-1.313.469-2.383 1.234-3.223-.121-.3-.535-1.523.117-3.175 0 0 1.008-.32 3.301 1.23A11.487 11.487 0 0116 9.805c1.02.004 2.047.136 3.004.402 2.293-1.55 3.297-1.23 3.297-1.23.656 1.652.246 2.875.12 3.175.77.84 1.231 1.91 1.231 3.223 0 4.61-2.804 5.621-5.476 5.922.43.367.812 1.101.812 2.219 0 1.605-.011 2.898-.011 3.293 0 .32.214.695.824.578C24.566 25.797 28 21.3 28 16c0-6.629-5.371-12-12-12z" />
Expand All @@ -47,7 +47,7 @@
</svg>
<span class="ml-3"> Sign In </span>
</button>
<button class="signup-button mt-5 tracking-wide font-semibold bg-indigo-500 text-gray-100 w-full py-4 rounded-lg hover:bg-indigo-700 transition-all duration-300 ease-in-out flex items-center justify-center focus:shadow-outline focus:outline-none" onclick="window.location.href='https://flux.codegasms.com/register'">
<button class="signup-button mt-5 tracking-wide font-semibold bg-indigo-500 text-gray-100 w-full py-4 rounded-lg hover:bg-indigo-700 transition-all duration-300 ease-in-out flex items-center justify-center focus:shadow-outline focus:outline-none" onclick="window.location.href='<%- params.server_url %>/register'">
<svg class="w-6 h-6 -ml-2" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M16 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2" />
<circle cx="8.5" cy="7" r="4" />
Expand Down Expand Up @@ -81,7 +81,7 @@
const email = document.querySelector('input[type="email"]').value;
const password = document.querySelector('input[type="password"]').value;

await fetch('https://api.flux.codegasms.com/auth/login', {
await fetch('<%- params.server_api %>/auth/login', {
method: 'POST',
headers: {
'accept': 'application/json',
Expand All @@ -103,4 +103,4 @@
});
});
</script>
<%- await include("../layouts/end.ejs") %>
<%- await include("../layouts/end.ejs") %>
4 changes: 2 additions & 2 deletions client/views/mods/pricing/index.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%- await include("../../layouts/header.ejs", {title: 'FLUX Mods Pricing' }) %>

<%
const response = await fetch('https://api.flux.codegasms.com/mods/token-plans', {
const response = await fetch(`${params.server_api}/mods/token-plans`, {
method: 'GET',
headers: {
accept: 'application/json',
Expand Down Expand Up @@ -128,4 +128,4 @@ const averageHalfYearlyDiscount = parseInt(halfYearlyDiscounts / updatedPlans.le
</section>
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
<script type="module" src="/js/flux-mods/pricing.js"></script>
<%- await include("../../layouts/end.ejs") %>
<%- await include("../../layouts/end.ejs") %>
4 changes: 2 additions & 2 deletions client/views/partials/admin/token-plans-create.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"summary": summary
}

let response = await fetch("https://api.flux.codegasms.com" + '/mods/token-plans/' + planId, {
let response = await fetch('<%- params.server_api %>/mods/token-plans/' + planId, {
method: 'POST',
credentials: 'include',
headers: {
Expand All @@ -94,4 +94,4 @@
console.log(result);
alert("Plan: " + result.planID + " created successfully!");
});
</script>
</script>
5 changes: 3 additions & 2 deletions client/views/partials/admin/user-create.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@

// console.log(hashedPassword);

const response = await fetch('https://api.flux.codegasms.com/users', {
const server_api = '<%- params.server_api %>';
const response = await fetch(`${server_api}/users`, {
method: 'POST',
credentials: 'include',
headers: {
Expand All @@ -78,4 +79,4 @@
})
}).then(res => res.json()).then(data => console.log(data));
});
</script>
</script>
12 changes: 6 additions & 6 deletions client/views/register/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<h1 class="text-2xl xl:text-3xl font-extrabold">Sign up</h1>
<div class="w-full flex-1 mt-8">
<div class="flex flex-col items-center">
<!-- <a href="https://api.flux.codegasms.com/oauth/google"> -->
<button class="w-full max-w-xs font-bold shadow-sm rounded-lg py-3 bg-indigo-100 text-gray-800 flex items-center justify-center transition-all duration-300 ease-in-out focus:outline-none hover:shadow focus:shadow-sm focus:shadow-outline" onclick="window.location.href='https://api.flux.codegasms.com/oauth/google'">
<!-- <a href="<%- params.server_api %>/oauth/google"> -->
<button class="w-full max-w-xs font-bold shadow-sm rounded-lg py-3 bg-indigo-100 text-gray-800 flex items-center justify-center transition-all duration-300 ease-in-out focus:outline-none hover:shadow focus:shadow-sm focus:shadow-outline" onclick="window.location.href='<%- params.server_api %>/oauth/google'">
<div class="bg-white p-2 rounded-full">
<svg class="w-4" viewBox="0 0 533.5 544.3">
<path d="M533.5 278.4c0-18.5-1.5-37.1-4.7-55.3H272.1v104.8h147c-6.1 33.8-25.7 63.7-54.4 82.7v68h87.7c51.5-47.4 81.1-117.4 81.1-200.2z" fill="#4285f4" />
Expand All @@ -22,7 +22,7 @@
</button>
<!-- </a> -->

<button class="w-full max-w-xs font-bold shadow-sm rounded-lg py-3 bg-indigo-100 text-gray-800 flex items-center justify-center transition-all duration-300 ease-in-out focus:outline-none hover:shadow focus:shadow-sm focus:shadow-outline mt-5" onclick="window.location.href='https://api.flux.codegasms.com/oauth/github'">
<button class="w-full max-w-xs font-bold shadow-sm rounded-lg py-3 bg-indigo-100 text-gray-800 flex items-center justify-center transition-all duration-300 ease-in-out focus:outline-none hover:shadow focus:shadow-sm focus:shadow-outline mt-5" onclick="window.location.href='<%- params.server_api %>/oauth/github'">
<div class="bg-white p-1 rounded-full">
<svg class="w-6" viewBox="0 0 32 32">
<path fill-rule="evenodd" d="M16 4C9.371 4 4 9.371 4 16c0 5.3 3.438 9.8 8.207 11.387.602.11.82-.258.82-.578 0-.286-.011-1.04-.015-2.04-3.34.723-4.043-1.609-4.043-1.609-.547-1.387-1.332-1.758-1.332-1.758-1.09-.742.082-.726.082-.726 1.203.086 1.836 1.234 1.836 1.234 1.07 1.836 2.808 1.305 3.492 1 .11-.777.422-1.305.762-1.605-2.664-.301-5.465-1.332-5.465-5.93 0-1.313.469-2.383 1.234-3.223-.121-.3-.535-1.523.117-3.175 0 0 1.008-.32 3.301 1.23A11.487 11.487 0 0116 9.805c1.02.004 2.047.136 3.004.402 2.293-1.55 3.297-1.23 3.297-1.23.656 1.652.246 2.875.12 3.175.77.84 1.231 1.91 1.231 3.223 0 4.61-2.804 5.621-5.476 5.922.43.367.812 1.101.812 2.219 0 1.605-.011 2.898-.011 3.293 0 .32.214.695.824.578C24.566 25.797 28 21.3 28 16c0-6.629-5.371-12-12-12z" />
Expand Down Expand Up @@ -50,7 +50,7 @@
</svg>
<span class="ml-3"> Sign Up </span>
</button>
<button class="signin-button mt-5 tracking-wide font-semibold bg-indigo-500 text-gray-100 w-full py-4 rounded-lg hover:bg-indigo-700 transition-all duration-300 ease-in-out flex items-center justify-center focus:shadow-outline focus:outline-none" onclick="window.location.href='https://flux.codegasms.com/login'">
<button class="signin-button mt-5 tracking-wide font-semibold bg-indigo-500 text-gray-100 w-full py-4 rounded-lg hover:bg-indigo-700 transition-all duration-300 ease-in-out flex items-center justify-center focus:shadow-outline focus:outline-none" onclick="window.location.href='<%- params.server_api %>/login'">
<svg class="w-6 h-6 -ml-2" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M16 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2" />
<circle cx="8.5" cy="7" r="4" />
Expand Down Expand Up @@ -85,7 +85,7 @@
const name = document.querySelector('input[type="text"]').value;
const password = document.querySelector('input[type="password"]').value;

await fetch('https://api.flux.codegasms.com/auth/register', {
await fetch('<%- params.server_api %>/auth/register', {
method: 'POST',
headers: {
'accept': 'application/json',
Expand All @@ -108,4 +108,4 @@
});
});
</script>
<%- await include("../layouts/end.ejs") %>
<%- await include("../layouts/end.ejs") %>
4 changes: 2 additions & 2 deletions client/views/space/[fileID]/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<!-- Search bar -->
<%- await include("../../components/space/topbar.ejs", {username: params.fileID}) %>
<!-- Main page -->
<%- await include("../../components/space/main.ejs", {path: params.fileID}) %>
<%- await include("../../components/space/main.ejs", {path: params.fileID, params: params}) %>
<!-- Right panel -->
<%#- await include("../components/space/rightpanel.ejs") %>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="/js/space/space.js"></script>
<%- await include("../../layouts/end.ejs") %>
</div>
</div>
2 changes: 1 addition & 1 deletion client/views/space/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<!-- Search bar -->
<%- await include("../components/space/topbar.ejs", {username:"test"}) %>
<!-- Main page -->
<%- await include("../components/space/main.ejs", {path: "/"}) %>
<%- await include("../components/space/main.ejs", {path: "/", params: params}) %>
<!-- Right panel -->
<%#- await include("../components/space/rightpanel.ejs") %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions client/views/space/pricing/index.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%- await include("../../layouts/header.ejs", {title: 'FLUX Spaces Pricing' }) %>

<%
const response = await fetch('https://api.flux.codegasms.com/spaces/quotas', {
const response = await fetch(`${params.server_api}/spaces/quotas`, {
method: 'GET',
headers: {
accept: 'application/json',
Expand Down Expand Up @@ -127,4 +127,4 @@ const averageHalfYearlyDiscount = parseInt(halfYearlyDiscounts / updatedPlans.le
</section>
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
<script type="module" src="/js/space/pricing.js"></script>
<%- await include("../../layouts/end.ejs") %>
<%- await include("../../layouts/end.ejs") %>
4 changes: 2 additions & 2 deletions client/views/space/shared/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<!-- Search bar -->
<%- await include("../../components/space/topbar.ejs", {username: params.fileID}) %>
<!-- Main page -->
<%# await include("../../components/space/main.ejs") %>
<%# await include("../../components/space/main.ejs", {params: params}) %>
<div class="w-full h-full flex justify-center items-center text-[32px] text-center">
Sharing feature is </br>
Coming soon...!
Expand All @@ -18,4 +18,4 @@
<script src="/js/space/space.js"></script>
</div>

<%- await include("../../layouts/end.ejs") %>
<%- await include("../../layouts/end.ejs") %>
Loading