Skip to content

Commit cf36e2a

Browse files
committed
comment server file, edit workflow to skip if env secrets are not available to test bc of forked repo
1 parent 70eeeaa commit cf36e2a

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

.github/workflows/node.js.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ jobs:
2626
cache: 'npm'
2727
- run: npm ci
2828
- run: npm run build --if-present
29-
- name: Start server
29+
- name: Start server (only if secrets are available)
30+
if: ${{ env.USER_DB_USER != '' }}
3031
env:
3132
USER_DB_USER: ${{secrets.USER_DB_USER}}
3233
USER_DB_PW: ${{secrets.USER_DB_PW}}
3334
USER_DB_URL: ${{secrets.USER_DB_URL}}
3435
SSL_KEY: ${{secrets.SSL_KEY}}
3536
SSL_CERT: ${{secrets.SSL_CERT}}
3637
run: npm run start:test
37-
- name: Run test suites
38+
- name: Run test suites (only if secrets are available)
39+
if: ${{ env.MYSQL_TEST_URL != '' || env.PG_TEST_URL != '' }}
3840
env:
3941
MYSQL_TEST_URL: ${{secrets.MYSQL_TEST_URL}}
4042
MYSQL_TEST_USERNAME: ${{secrets.MYSQL_TEST_USERNAME}}

server/server.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,32 @@ import session from 'express-session';
88
import cookieParser from 'cookie-parser';
99
import bodyParser from 'body-parser';
1010

11-
config();
11+
config(); // load .env variables
1212

13+
const app: Express = express();
1314
const port: number = Number(process.env.PORT) || 3000;
1415

15-
const app: Express = express();
1616
//Set the payload limit size to 1mb when save a large database data which is TableData in featureTab.
1717
app.use(bodyParser.json({ limit: '1mb' }));
1818
app.use(bodyParser.urlencoded({ limit: '1mb', extended: true }));
1919

20+
// Core express middlewares
2021
app.use(express.json());
2122
app.use(express.urlencoded({ extended: true }));
23+
24+
// Cookies and CORS
2225
app.use(cookieParser());
2326
app.use(cors());
27+
28+
// Serve static files from 'dist'
2429
app.use(express.static(path.join(__dirname, '../dist')));
30+
31+
// Session setup
32+
if (!process.env.SESSION_SECRET) {
33+
console.error('❌ SESSION_SECRET is not defined in environment variables!');
34+
process.exit(1); // Exit early if SESSION_SECRET is missing
35+
}
36+
2537
app.use(
2638
session({
2739
secret: process.env.SESSION_SECRET as string,
@@ -31,15 +43,16 @@ app.use(
3143
secure: false,
3244
httpOnly: true,
3345
path: '/',
34-
sameSite: true,
46+
sameSite: 'lax',
3547
maxAge: 24 * 60 * 60 * 1000,
3648
},
3749
})
3850
);
3951

52+
// Start the server
4053
app.listen(port, () => {
41-
log.info(`Securely Running at ${port}`);
42-
routes(app);
54+
log.info(`✅ Server running securely at ${port}`);
55+
routes(app); // register routes AFTER all middlewares
4356
});
4457

4558
export default app;

0 commit comments

Comments
 (0)